Class: ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/ecrire/app/controllers/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#current_userObject



7
8
9
# File 'lib/ecrire/app/controllers/application_controller.rb', line 7

def current_user
  warden.user
end

#signed_in?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/ecrire/app/controllers/application_controller.rb', line 11

def signed_in?
  !warden.user.nil?
end

#url(path, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ecrire/app/controllers/application_controller.rb', line 15

def url(path, options = {})
  records = options.with_indifferent_access
  regex = /(:([a-z]+)\.([a-z]+))/i
  path = path.gsub regex do |match|
    records[$2].send($3)
  end

  if options.delete(:full_path)
    options[:path] = path
    options[:host] ||= request.host
    options[:protocol] ||= request.protocol
    options[:port] ||= request.port
    ActionDispatch::Http::URL.full_url_for(options)
  else
    path
  end
end