class Controller
Public Class Methods
new(request)
click to toggle source
Set request object as an attribute accessible with @request variable.
# File lib/jails/controller.rb, line 5 def initialize(request) @request = request puts("\s Parameters #{@request.params}") end
Public Instance Methods
params()
click to toggle source
helper method, params returns @request.params
# File lib/jails/controller.rb, line 11 def params @request.params end
redirect_to(path)
click to toggle source
Return Rack response with header field Location assigned to path in argument.
# File lib/jails/controller.rb, line 48 def redirect_to(path) response = Rack::Response.new([], 302, {"Location" => path}) return response end
render()
click to toggle source
Return Rack response object with the erb template.
# File lib/jails/controller.rb, line 16 def render resource = params[:resource] action = params[:action] template = "#{resource}/#{action}.html.erb" file = File.join('app', 'views', template) if File.exist?(file) puts("\s Rendering #{template}") # Prints in log render_template = ERB.new(File.read(file)).result(binding) puts "\s Rendered #{template}" response = Rack::Response.new([render_template], 200, {"Content-Type" => "text/html"}) puts "Completed 200 OK" return response else puts("\s Missing Template #{template}.") response = Rack::Response.new(["Nothing found"], 404, {"Content-Type" => "text/html"}) return response end end
render_partial(template)
click to toggle source
Return rendered partial template to be inserted into the parent template that called it.
# File lib/jails/controller.rb, line 36 def render_partial(template) file = File.join('app', 'views', template) if File.exists?(file) rendered_partial = ERB.new(File.read(file)).result(binding) puts "\s Rendered #{template}" return rendered_partial else puts("\s Missing Template #{template}.") end end