Class: ActionController::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/required/application_controller.rb

Direct Known Subclasses

PixelearthBase::ApplicationController

Instance Method Summary collapse

Instance Method Details

#app_controllersObject



73
74
75
# File 'lib/required/application_controller.rb', line 73

def app_controllers
  Dir['app/controllers/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize}
end

#app_modelsObject



76
77
78
# File 'lib/required/application_controller.rb', line 76

def app_models
  Dir['app/models/*.rb'].map {|f| File.basename(f, '.*').camelize.constantize }
end

#get_resourceObject

gets @resource or @resource for all actions in controller before filter is set per controller, thus overrideable.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/required/application_controller.rb', line 31

def get_resource                                                                      
  action     = params[:action].to_sym
  controller = params[:controller]
  klass      = controller.classify.constantize 

  if [:show, :edit, :update, :destroy].include? action
    @resource = klass.find(params[:id])
  elsif action == :new
    @resource = klass.new
  elsif action == :create
    @resource = klass.new(params[controller.singularize])
  elsif action == :index
    @resources = klass.all
  end
  
end

#h1(st) ⇒ Object

allow templates to set page h1



52
53
54
# File 'lib/required/application_controller.rb', line 52

def h1 (st)                                                                            #allow templates to set page h1
  @layout[:h1] = st
end

#h1_emph(st) ⇒ Object

uniform way to make part of the h1 stand out



59
60
61
# File 'lib/required/application_controller.rb', line 59

def h1_emph(st)                                                                        #uniform way to make part of the h1 stand out
  "<em>#{st}</em>"
end

#h1_name(st) ⇒ Object

uniform way of displaying model names in h1



62
63
64
# File 'lib/required/application_controller.rb', line 62

def h1_name(st)                                                                        #uniform way of displaying model names in h1 
  h1_emph "\"#{st.titleize}\""
end

#init_pixelearth_application_controllerObject

base config for layout, actions can add to this



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/required/application_controller.rb', line 15

def init_pixelearth_application_controller                                           #base config for layout, actions can add to this
  @layout = {
              :show_h1      => true,
              :title        => nil,
              :h1           => nil,
              :css          => [  
                                  'sass/compiled/pixelearth',
                                  'sass/compiled/validation_errors',
                               ],
              :js           => []
  }
end

#strip_tags(str) ⇒ Object

———– UTILS ————–



67
68
69
# File 'lib/required/application_controller.rb', line 67

def strip_tags (str)
  str.gsub(/<\/?[^>]*>/, "")
end

#title(st) ⇒ Object

———– LAYOUT ————–



49
50
51
# File 'lib/required/application_controller.rb', line 49

def title (st)                                                                         #allow templates to set page title
  @layout[:title] = strip_tags st 
end

#title_h1(st) ⇒ Object

allow templates to set page title and h1 at same time



55
56
57
58
# File 'lib/required/application_controller.rb', line 55

def title_h1 (st)                                                                      #allow templates to set page title and h1 at same time
  h1(st)
  title(st)
end

#tweet(st = '') ⇒ Object



70
71
72
# File 'lib/required/application_controller.rb', line 70

def tweet(st='')
  puts "-----------#{st}----------------".green
end