class AutoForme::Frameworks::Rails::Request

  1. lib/autoforme/frameworks/rails.rb
Superclass: Request

Methods

Public Class

  1. new

Public Instance

  1. csrf_token_hash
  2. redirect
  3. xhr?

Public Class methods

new(request)
[show source]
   # File lib/autoforme/frameworks/rails.rb
 7 def initialize(request)
 8   @controller = request
 9   @params = request.params
10   @session = request.session
11   @env = request.request.env
12   @method = @env['REQUEST_METHOD']
13   @model = @params['autoforme_model']
14   @action_type = @params['autoforme_action']
15   @path = @env['SCRIPT_NAME']
16   @id = @params['id']
17   @id = nil if @id && @id.empty?
18 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
32 def csrf_token_hash(action=nil)
33   vc = @controller.view_context
34   {vc.request_forgery_protection_token.to_s=>vc.form_authenticity_token} if vc.protect_against_forgery?
35 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
22 def redirect(path)
23   throw :redirect, path
24 end
xhr?()

Whether the request is an asynchronous request

[show source]
   # File lib/autoforme/frameworks/rails.rb
27 def xhr?
28   @controller.request.xhr?
29 end