Class: AutoForme::Frameworks::Rails::Request

Inherits:
Request
  • Object
show all
Defined in:
lib/autoforme/frameworks/rails.rb

Instance Attribute Summary

Attributes inherited from Request

#action_type, #controller, #env, #id, #method, #model, #params, #path, #session

Instance Method Summary collapse

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.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/autoforme/frameworks/rails.rb', line 7

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']
  @id = nil if @id && @id.empty?
end

Instance Method Details

#csrf_token_hashObject

Use Rails’s form_authenticity_token for CSRF protection.



32
33
34
35
# File 'lib/autoforme/frameworks/rails.rb', line 32

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.



22
23
24
# File 'lib/autoforme/frameworks/rails.rb', line 22

def redirect(path)
  throw :redirect, path
end

#xhr?Boolean

Whether the request is an asynchronous request

Returns:

  • (Boolean)


27
28
29
# File 'lib/autoforme/frameworks/rails.rb', line 27

def xhr?
  @controller.request.xhr?
end