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, line 6
def initialize(request)
  @controller = request
  @params = request.params
  @session = request.session
  @env = request.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

Public Instance methods

csrf_token_hash ()

Use Rails's form_authenticity_token for CSRF protection.

[show source]
# File lib/autoforme/frameworks/rails.rb, line 31
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)

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, line 21
def redirect(path)
  throw :redirect, path
end
xhr? ()

Whether the request is an asynchronous request

[show source]
# File lib/autoforme/frameworks/rails.rb, line 26
def xhr?
  @controller.request.xhr?
end