Module: Rodauth::Rails::Feature::Base

Extended by:
ActiveSupport::Concern
Defined in:
lib/rodauth/rails/feature/base.rb

Instance Method Summary collapse

Instance Method Details

#clear_sessionObject

Reset Rails session to protect from session fixation attacks.



21
22
23
# File 'lib/rodauth/rails/feature/base.rb', line 21

def clear_session
  rails_controller_instance.reset_session
end

#flash_error_keyObject

Default the flash error key to Rails’ default :alert.



26
27
28
# File 'lib/rodauth/rails/feature/base.rb', line 26

def flash_error_key
  :alert
end

#rails_accountObject



15
16
17
18
# File 'lib/rodauth/rails/feature/base.rb', line 15

def 
  @rails_account = nil if .nil? || @rails_account&.id != 
  @rails_account ||=  if account!
end

#rails_account_modelObject



43
44
45
46
47
48
49
# File 'lib/rodauth/rails/feature/base.rb', line 43

def 
  table = accounts_table
  table = table.column if table.is_a?(Sequel::SQL::QualifiedIdentifier) # schema is specified
  table.to_s.classify.constantize
rescue NameError
  raise Error, "cannot infer account model, please set `rails_account_model` in your rodauth configuration"
end

#rails_controllerObject



35
36
37
38
39
40
41
# File 'lib/rodauth/rails/feature/base.rb', line 35

def rails_controller
  if only_json? && ::Rails.configuration.api_only
    ActionController::API
  else
    ActionController::Base
  end
end

#rails_controller_eval(&block) ⇒ Object

Evaluates the block in context of a Rodauth controller instance.



31
32
33
# File 'lib/rodauth/rails/feature/base.rb', line 31

def rails_controller_eval(&block)
  rails_controller_instance.instance_exec(&block)
end

#sessionObject



53
54
55
56
57
# File 'lib/rodauth/rails/feature/base.rb', line 53

def session
  super
rescue Roda::RodaError
  fail Rodauth::Rails::Error, "There is no session middleware configured, see instructions on how to add it: https://guides.rubyonrails.org/api_app.html#using-session-middlewares"
end