9 class ApplicationController
10 helper_method :logged_in?
19 stylesheet_link_tag :monkey
20 javascript_link_tag :monkey
24 # http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html
26 - form_for @person do |f|
28 = f.label :first_name, "First name"
29 = f.text_field :first_name
32 = f.text_field :last_name>
34 - fields_for @person.permission do |fields|
35 = fields.checkbox :admin
37 -# name="person[admin]"
38 - fields_for :person, @client do |fields|
39 = fields.checkbox :admin
43 # Also: check_box, email_field, fields_for
44 # file_field, hidden_field, label, number_field, password_field
45 # radio_button, range_field, search_field, telephonen_field,
46 # text_area, text_field, url_field
51 http://apidock.com/rails/ActionController/Base
53 class ProjectsController
54 layout 'project' # Actually defaults to `projects` based
55 # on the controller name
66 class ApplicationController < ActionController::Base
67 before_filter :validate, only: [:save, :edit]
68 before_filter :ensure_auth, except: [:logout]
70 before_filter :require_login
76 flash[:error] = "You must be logged in to access this section"
77 redirect_to new_login_url # halts request cycle
82 ### Default URL options
84 class ApplicationController < ActionController::Base
85 # The options parameter is the hash passed in to 'url_for'
86 def default_url_options(options)
87 {:locale => I18n.locale}
94 flash[:notice] = "Your session expired"
99 class UsersController < ApplicationController
102 respond_to do |format|
103 format.html # index.html.erb
104 format.xml { render :xml => @users}
105 format.json { render :json => @users}
112 redirect_to action: 'show', id: @entry.id
113 redirect_to root_url # a path
118 render template: 'products/show'
120 render status: :forbidden
122 render layout: 'special_layout'
124 render action: 'something' # same as `file: 'my/something'`
125 # Renders the template only, does not execute
131 render location: photo_url(photo)
133 ### Head-only responses
136 head :created, location: photo_path(@photo)
141 # app/views/layouts/application.html.erb
142 <%= content_for?(:content) ? yield :content : yield %>
144 # app/views/layouts/news.html.erb
145 <% content_for :content do %>
148 <% render template: :'layouts/application' %>