Class: AutoForme::Frameworks::Rails::Request
- Defined in:
- lib/autoforme/frameworks/rails.rb
Instance Attribute Summary
Attributes inherited from Request
#action_type, #controller, #id, #method, #model, #params, #path, #session
Instance Method Summary collapse
-
#csrf_token_hash ⇒ Object
Use Rails’s form_authenticity_token for CSRF protection.
-
#initialize(request) ⇒ Request
constructor
A new instance of Request.
-
#redirect(path) ⇒ Object
Implement redirects in the Rails support using throw/catch, similar to how they are natively implemented in Sinatra.
-
#xhr? ⇒ Boolean
Whether the request is an asynchronous request.
Methods inherited from Request
#post?, #query_string, #set_flash_notice, #set_flash_now_error
Constructor Details
#initialize(request) ⇒ Request
Returns a new instance of Request.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/autoforme/frameworks/rails.rb', line 5 def initialize(request) @controller = request @params = request.params @session = request.session @env = request.env @method = @env['REQUEST_METHOD'] @model = @params['autoforme_model'] @action_type = @params['autoforme_action'] @path = @env['SCRIPT_NAME'] @id = @params['id'] end |
Instance Method Details
#csrf_token_hash ⇒ Object
Use Rails’s form_authenticity_token for CSRF protection.
29 30 31 32 |
# File 'lib/autoforme/frameworks/rails.rb', line 29 def csrf_token_hash vc = @controller.view_context {vc.request_forgery_protection_token.to_s=>vc.form_authenticity_token} if vc.protect_against_forgery? end |
#redirect(path) ⇒ Object
Implement redirects in the Rails support using throw/catch, similar to how they are natively implemented in Sinatra.
19 20 21 |
# File 'lib/autoforme/frameworks/rails.rb', line 19 def redirect(path) throw :redirect, path end |
#xhr? ⇒ Boolean
Whether the request is an asynchronous request
24 25 26 |
# File 'lib/autoforme/frameworks/rails.rb', line 24 def xhr? @controller.request.xhr? end |