Module: Incline::Extensions::ActionControllerBase
- Defined in:
- lib/incline/extensions/action_controller_base.rb
Overview
Adds some extra functionality to the base controller definition.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Enforces SSL and catches Incline::NotLoggedIn exceptions.
Instance Method Summary collapse
-
#redirect_back_or(default) ⇒ Object
A redirects to a previously stored location or to the default location.
-
#render_csv(filename = nil, view_name = nil) ⇒ Object
Renders the view as a CSV file.
-
#store_location ⇒ Object
Stores the current URL to be used with #redirect_back_or.
Class Method Details
.included(base) ⇒ Object
Enforces SSL and catches Incline::NotLoggedIn exceptions.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/incline/extensions/action_controller_base.rb', line 172 def self.included(base) base.extend ClassMethods base.class_eval do # Force SSL under production environments unless allow_http_for_request returns true. if Rails.env.production? force_ssl unless: :allow_http_for_request? end # Process user authorization for all actions except the GET/POST api actions. # These get to be authorized once the actual action is selected. before_action :valid_user?, except: [ :api ] undef process_action ## # Override the default to enable auto-api behavior if desired. def process_action(method_name, *args) #:nodoc: if self.class.auto_api? unless process_api_action(false, nil) super method_name, *args end else super method_name, *args end end rescue_from ::Incline::NotLoggedIn do |exception| flash[:info] = exception. store_location redirect_to(incline.login_url) end end end |
Instance Method Details
#redirect_back_or(default) ⇒ Object
A redirects to a previously stored location or to the default location.
Usually this will be used to return to an action after a user logs in.
230 231 232 233 |
# File 'lib/incline/extensions/action_controller_base.rb', line 230 def redirect_back_or(default) redirect_to session[:forwarding_url] || default session.delete :forwarding_url end |
#render_csv(filename = nil, view_name = nil) ⇒ Object
Renders the view as a CSV file.
Set the filename
you would like to provide to the client, or leave it nil to use the action name. Set the view_name
you would like to render, or leave it nil to use the action name.
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/incline/extensions/action_controller_base.rb', line 213 def render_csv(filename = nil, view_name = nil) filename ||= params[:action] view_name ||= params[:action] filename.downcase! filename += '.csv' unless filename[-4..-1] == '.csv' headers['Content-Type'] = 'text/csv' headers['Content-Disposition'] = "attachment; filename=\"#{filename}\"" render view_name, layout: false end |
#store_location ⇒ Object
Stores the current URL to be used with #redirect_back_or.
237 238 239 |
# File 'lib/incline/extensions/action_controller_base.rb', line 237 def store_location session[:forwarding_url] = request.url if request.get? end |