Public Class methods
new(request)
[show source]
# File lib/autoforme/frameworks/rails.rb 7 def initialize(request) 8 @controller = request 9 @params = {} 10 request.params.each do |k, v| 11 @params[k] = v 12 end 13 @session = request.session 14 @env = request.request.env 15 @method = @env['REQUEST_METHOD'] 16 @model = @params['autoforme_model'] 17 @action_type = @params['autoforme_action'] 18 @path = @env['SCRIPT_NAME'] 19 @id = @params['id'] 20 @id = nil if @id && @id.empty? 21 end
Public Instance methods
csrf_token_hash(action=nil)
Use Rails’s form_authenticity_token for CSRF protection.
[show source]
# File lib/autoforme/frameworks/rails.rb 35 def csrf_token_hash(action=nil) 36 vc = @controller.view_context 37 # :nocov: 38 if vc.protect_against_forgery? 39 # :nocov: 40 {vc.request_forgery_protection_token.to_s=>vc.form_authenticity_token} 41 end 42 end
redirect(path)
Implement redirects in the Rails
support using throw/catch, similar to how they are natively implemented in Sinatra
.
[show source]
# File lib/autoforme/frameworks/rails.rb 25 def redirect(path) 26 throw :redirect, path 27 end
xhr?()
Whether the request is an asynchronous request
[show source]
# File lib/autoforme/frameworks/rails.rb 30 def xhr? 31 @controller.request.xhr? 32 end