Implement Sandbox
This commit is contained in:
committed by
Amaia Castro
parent
70bb08564f
commit
b35683f75e
45
app/controllers/sandbox_controller.rb
Normal file
45
app/controllers/sandbox_controller.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
class SandboxController < ApplicationController
|
||||
skip_authorization_check
|
||||
|
||||
layout :set_layout
|
||||
|
||||
helper_method(:namespace)
|
||||
|
||||
def index
|
||||
@templates = Dir.glob(Rails.root.join('app/views/sandbox/*.html.erb').to_s).map do |filename|
|
||||
filename = File.basename(filename, File.extname(filename))
|
||||
filename unless filename.starts_with?('_') || filename == 'index.html'
|
||||
end.compact
|
||||
end
|
||||
|
||||
def show
|
||||
if params[:template].index('.') # CVE-2014-0130
|
||||
render :action => "index"
|
||||
elsif lookup_context.exists?("sandbox/#{params[:template]}")
|
||||
if params[:template] == "index"
|
||||
render :action => "index"
|
||||
else
|
||||
render "sandbox/#{params[:template]}"
|
||||
end
|
||||
|
||||
elsif lookup_context.exists?("sandbox/#{params[:template]}/index")
|
||||
render "sandbox/#{params[:template]}/index"
|
||||
else
|
||||
render :action => "index"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_layout
|
||||
if params[:template] && params[:template].split("_").first == "admin"
|
||||
"admin"
|
||||
else
|
||||
"application"
|
||||
end
|
||||
end
|
||||
|
||||
def namespace
|
||||
"admin"
|
||||
end
|
||||
end
|
||||
13
app/views/sandbox/index.html.erb
Normal file
13
app/views/sandbox/index.html.erb
Normal file
@@ -0,0 +1,13 @@
|
||||
<div id="main-content" class="container">
|
||||
<div class="eight columns">
|
||||
<div class="row">
|
||||
<h1>Welcome to sandbox</h1>
|
||||
|
||||
<ul>
|
||||
<% @templates.each do |template| %>
|
||||
<li><%= link_to template, "/sandbox/" + template %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,5 +1,10 @@
|
||||
Rails.application.routes.draw do
|
||||
|
||||
if Rails.env.development? || Rails.env.staging?
|
||||
get '/sandbox' => 'sandbox#index'
|
||||
get '/sandbox/*template' => 'sandbox#show'
|
||||
end
|
||||
|
||||
devise_for :users, controllers: {
|
||||
registrations: 'users/registrations',
|
||||
sessions: 'users/sessions',
|
||||
|
||||
Reference in New Issue
Block a user