annotate app/controllers/application_controller.rb @ 1469:c77ab1edff6b bug_563

Close obsolete branch bug_563
author Chris Cannam
date Wed, 23 Jan 2013 14:12:47 +0000
parents 5e80956cc792
children bb32da3bea34
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@441 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@441 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 require 'uri'
Chris@0 19 require 'cgi'
Chris@0 20
Chris@507 21 class Unauthorized < Exception; end
Chris@507 22
Chris@0 23 class ApplicationController < ActionController::Base
Chris@0 24 include Redmine::I18n
Chris@0 25
Chris@0 26 layout 'base'
Chris@117 27 exempt_from_layout 'builder', 'rsb'
Chris@441 28
Chris@909 29 protect_from_forgery
Chris@909 30 def handle_unverified_request
Chris@909 31 super
Chris@909 32 cookies.delete(:autologin)
Chris@909 33 end
Chris@0 34 # Remove broken cookie after upgrade from 0.8.x (#4292)
Chris@0 35 # See https://rails.lighthouseapp.com/projects/8994/tickets/3360
Chris@0 36 # TODO: remove it when Rails is fixed
Chris@0 37 before_filter :delete_broken_cookies
Chris@0 38 def delete_broken_cookies
Chris@0 39 if cookies['_redmine_session'] && cookies['_redmine_session'] !~ /--/
Chris@441 40 cookies.delete '_redmine_session'
Chris@0 41 redirect_to home_path
Chris@0 42 return false
Chris@0 43 end
Chris@0 44 end
Chris@441 45
Chris@0 46 before_filter :user_setup, :check_if_login_required, :set_localization
Chris@0 47 filter_parameter_logging :password
Chris@441 48
Chris@0 49 rescue_from ActionController::InvalidAuthenticityToken, :with => :invalid_authenticity_token
Chris@507 50 rescue_from ::Unauthorized, :with => :deny_access
Chris@441 51
Chris@0 52 include Redmine::Search::Controller
Chris@0 53 include Redmine::MenuManager::MenuController
Chris@0 54 helper Redmine::MenuManager::MenuHelper
Chris@441 55
Chris@0 56 Redmine::Scm::Base.all.each do |scm|
Chris@0 57 require_dependency "repository/#{scm.underscore}"
Chris@0 58 end
Chris@0 59
Chris@0 60 def user_setup
Chris@0 61 # Check the settings cache for each request
Chris@0 62 Setting.check_cache
Chris@0 63 # Find the current user
Chris@0 64 User.current = find_current_user
Chris@0 65 end
Chris@441 66
Chris@0 67 # Returns the current user or nil if no user is logged in
Chris@0 68 # and starts a session if needed
Chris@0 69 def find_current_user
Chris@0 70 if session[:user_id]
Chris@0 71 # existing session
Chris@0 72 (User.active.find(session[:user_id]) rescue nil)
Chris@0 73 elsif cookies[:autologin] && Setting.autologin?
Chris@0 74 # auto-login feature starts a new session
Chris@0 75 user = User.try_to_autologin(cookies[:autologin])
Chris@0 76 session[:user_id] = user.id if user
Chris@0 77 user
Chris@507 78 elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth?
Chris@0 79 # RSS key authentication does not start a session
Chris@0 80 User.find_by_rss_key(params[:key])
Chris@507 81 elsif Setting.rest_api_enabled? && accept_api_auth?
Chris@507 82 if (key = api_key_from_request)
Chris@0 83 # Use API key
Chris@117 84 User.find_by_api_key(key)
Chris@0 85 else
Chris@0 86 # HTTP Basic, either username/password or API key/random
Chris@0 87 authenticate_with_http_basic do |username, password|
Chris@0 88 User.try_to_login(username, password) || User.find_by_api_key(username)
Chris@0 89 end
Chris@0 90 end
Chris@0 91 end
Chris@0 92 end
Chris@0 93
Chris@0 94 # Sets the logged in user
Chris@0 95 def logged_user=(user)
Chris@0 96 reset_session
Chris@0 97 if user && user.is_a?(User)
Chris@0 98 User.current = user
Chris@0 99 session[:user_id] = user.id
Chris@0 100 else
Chris@0 101 User.current = User.anonymous
Chris@0 102 end
Chris@0 103 end
Chris@441 104
Chris@0 105 # check if login is globally required to access the application
Chris@0 106 def check_if_login_required
Chris@0 107 # no check needed if user is already logged in
Chris@0 108 return true if User.current.logged?
Chris@0 109 require_login if Setting.login_required?
Chris@441 110 end
Chris@441 111
Chris@0 112 def set_localization
Chris@0 113 lang = nil
Chris@0 114 if User.current.logged?
Chris@0 115 lang = find_language(User.current.language)
Chris@0 116 end
Chris@0 117 if lang.nil? && request.env['HTTP_ACCEPT_LANGUAGE']
Chris@0 118 accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
Chris@0 119 if !accept_lang.blank?
Chris@0 120 accept_lang = accept_lang.downcase
Chris@0 121 lang = find_language(accept_lang) || find_language(accept_lang.split('-').first)
Chris@0 122 end
Chris@0 123 end
Chris@0 124 lang ||= Setting.default_language
Chris@0 125 set_language_if_valid(lang)
Chris@0 126 end
Chris@441 127
Chris@0 128 def require_login
Chris@0 129 if !User.current.logged?
Chris@0 130 # Extract only the basic url parameters on non-GET requests
Chris@0 131 if request.get?
Chris@0 132 url = url_for(params)
Chris@0 133 else
Chris@0 134 url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], :project_id => params[:project_id])
Chris@0 135 end
Chris@0 136 respond_to do |format|
Chris@0 137 format.html { redirect_to :controller => "account", :action => "login", :back_url => url }
Chris@0 138 format.atom { redirect_to :controller => "account", :action => "login", :back_url => url }
Chris@0 139 format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
Chris@0 140 format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
Chris@0 141 format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="Redmine API"' }
Chris@0 142 end
Chris@0 143 return false
Chris@0 144 end
Chris@0 145 true
Chris@0 146 end
Chris@0 147
Chris@0 148 def require_admin
Chris@0 149 return unless require_login
Chris@0 150 if !User.current.admin?
Chris@0 151 render_403
Chris@0 152 return false
Chris@0 153 end
Chris@0 154 true
Chris@0 155 end
Chris@441 156
Chris@0 157 def deny_access
Chris@0 158 User.current.logged? ? render_403 : require_login
Chris@0 159 end
Chris@0 160
Chris@0 161 # Authorize the user for the requested action
Chris@0 162 def authorize(ctrl = params[:controller], action = params[:action], global = false)
chris@37 163 allowed = User.current.allowed_to?({:controller => ctrl, :action => action}, @project || @projects, :global => global)
chris@37 164 if allowed
chris@37 165 true
chris@37 166 else
chris@37 167 if @project && @project.archived?
chris@37 168 render_403 :message => :notice_not_authorized_archived_project
chris@37 169 else
chris@37 170 deny_access
chris@37 171 end
chris@37 172 end
Chris@0 173 end
Chris@0 174
Chris@0 175 # Authorize the user for the requested action outside a project
Chris@0 176 def authorize_global(ctrl = params[:controller], action = params[:action], global = true)
Chris@0 177 authorize(ctrl, action, global)
Chris@0 178 end
Chris@0 179
Chris@0 180 # Find project of id params[:id]
Chris@0 181 def find_project
Chris@0 182 @project = Project.find(params[:id])
Chris@0 183 rescue ActiveRecord::RecordNotFound
chris@743 184 User.current.logged? ? render_404 : require_login
Chris@0 185 end
Chris@0 186
chris@22 187 # Find project of id params[:project_id]
chris@22 188 def find_project_by_project_id
chris@22 189 @project = Project.find(params[:project_id])
chris@22 190 rescue ActiveRecord::RecordNotFound
chris@743 191 User.current.logged? ? render_404 : require_login
chris@22 192 end
chris@22 193
Chris@0 194 # Find a project based on params[:project_id]
Chris@0 195 # TODO: some subclasses override this, see about merging their logic
Chris@0 196 def find_optional_project
Chris@0 197 @project = Project.find(params[:project_id]) unless params[:project_id].blank?
Chris@0 198 allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true)
Chris@0 199 allowed ? true : deny_access
Chris@0 200 rescue ActiveRecord::RecordNotFound
Chris@0 201 render_404
Chris@0 202 end
Chris@0 203
Chris@0 204 # Finds and sets @project based on @object.project
Chris@0 205 def find_project_from_association
Chris@0 206 render_404 unless @object.present?
Chris@441 207
Chris@0 208 @project = @object.project
Chris@0 209 end
Chris@0 210
Chris@0 211 def find_model_object
Chris@0 212 model = self.class.read_inheritable_attribute('model_object')
Chris@0 213 if model
Chris@0 214 @object = model.find(params[:id])
Chris@0 215 self.instance_variable_set('@' + controller_name.singularize, @object) if @object
Chris@0 216 end
Chris@0 217 rescue ActiveRecord::RecordNotFound
Chris@0 218 render_404
Chris@0 219 end
Chris@0 220
Chris@0 221 def self.model_object(model)
Chris@0 222 write_inheritable_attribute('model_object', model)
Chris@0 223 end
Chris@14 224
Chris@14 225 # Filter for bulk issue operations
Chris@14 226 def find_issues
Chris@14 227 @issues = Issue.find_all_by_id(params[:id] || params[:ids])
Chris@14 228 raise ActiveRecord::RecordNotFound if @issues.empty?
Chris@441 229 if @issues.detect {|issue| !issue.visible?}
Chris@441 230 deny_access
Chris@441 231 return
Chris@441 232 end
chris@37 233 @projects = @issues.collect(&:project).compact.uniq
chris@37 234 @project = @projects.first if @projects.size == 1
chris@37 235 rescue ActiveRecord::RecordNotFound
chris@37 236 render_404
chris@37 237 end
Chris@441 238
chris@37 239 # Check if project is unique before bulk operations
chris@37 240 def check_project_uniqueness
chris@37 241 unless @project
Chris@14 242 # TODO: let users bulk edit/move/destroy issues from different projects
Chris@14 243 render_error 'Can not bulk edit/move/destroy issues from different projects'
Chris@14 244 return false
Chris@14 245 end
Chris@14 246 end
Chris@441 247
Chris@0 248 # make sure that the user is a member of the project (or admin) if project is private
Chris@0 249 # used as a before_filter for actions that do not require any particular permission on the project
Chris@0 250 def check_project_privacy
Chris@0 251 if @project && @project.active?
Chris@0 252 if @project.is_public? || User.current.member_of?(@project) || User.current.admin?
Chris@0 253 true
Chris@0 254 else
Chris@909 255 deny_access
Chris@0 256 end
Chris@0 257 else
Chris@0 258 @project = nil
Chris@0 259 render_404
Chris@0 260 false
Chris@0 261 end
Chris@0 262 end
Chris@0 263
Chris@14 264 def back_url
Chris@14 265 params[:back_url] || request.env['HTTP_REFERER']
Chris@14 266 end
Chris@14 267
Chris@0 268 def redirect_back_or_default(default)
Chris@0 269 back_url = CGI.unescape(params[:back_url].to_s)
Chris@0 270 if !back_url.blank?
Chris@0 271 begin
Chris@0 272 uri = URI.parse(back_url)
Chris@0 273 # do not redirect user to another host or to the login or register page
Chris@0 274 if (uri.relative? || (uri.host == request.host)) && !uri.path.match(%r{/(login|account/register)})
chris@365 275 # soundsoftware: if back_url is the home page,
chris@365 276 # change it to My Page (#125)
chris@365 277 if (uri.path == home_path)
chris@474 278 if (uri.path =~ /\/$/)
chris@474 279 uri.path = uri.path + "my"
chris@474 280 else
chris@474 281 uri.path = uri.path + "/my"
chris@474 282 end
chris@365 283 end
chris@237 284 # soundsoftware: if login page is https but back_url http,
chris@237 285 # switch back_url to https to ensure cookie validity (#83)
chris@237 286 if (uri.scheme == "http") && (URI.parse(request.url).scheme == "https")
chris@237 287 uri.scheme = "https"
chris@237 288 end
chris@365 289 back_url = uri.to_s
Chris@0 290 redirect_to(back_url)
Chris@0 291 return
Chris@0 292 end
Chris@0 293 rescue URI::InvalidURIError
Chris@0 294 # redirect to default
Chris@0 295 end
Chris@0 296 end
Chris@0 297 redirect_to default
Chris@441 298 false
Chris@0 299 end
Chris@441 300
chris@37 301 def render_403(options={})
Chris@0 302 @project = nil
chris@37 303 render_error({:message => :notice_not_authorized, :status => 403}.merge(options))
Chris@0 304 return false
Chris@0 305 end
Chris@441 306
chris@37 307 def render_404(options={})
chris@37 308 render_error({:message => :notice_file_not_found, :status => 404}.merge(options))
Chris@0 309 return false
Chris@0 310 end
Chris@441 311
chris@37 312 # Renders an error response
chris@37 313 def render_error(arg)
chris@37 314 arg = {:message => arg} unless arg.is_a?(Hash)
Chris@441 315
chris@37 316 @message = arg[:message]
chris@37 317 @message = l(@message) if @message.is_a?(Symbol)
chris@37 318 @status = arg[:status] || 500
Chris@441 319
Chris@0 320 respond_to do |format|
chris@37 321 format.html {
chris@37 322 render :template => 'common/error', :layout => use_layout, :status => @status
Chris@0 323 }
chris@37 324 format.atom { head @status }
chris@37 325 format.xml { head @status }
chris@37 326 format.js { head @status }
chris@37 327 format.json { head @status }
Chris@0 328 end
Chris@0 329 end
Chris@909 330
Chris@909 331 # Filter for actions that provide an API response
Chris@909 332 # but have no HTML representation for non admin users
Chris@909 333 def require_admin_or_api_request
Chris@909 334 return true if api_request?
Chris@909 335 if User.current.admin?
Chris@909 336 true
Chris@909 337 elsif User.current.logged?
Chris@909 338 render_error(:status => 406)
Chris@909 339 else
Chris@909 340 deny_access
Chris@909 341 end
Chris@909 342 end
Chris@14 343
Chris@14 344 # Picks which layout to use based on the request
Chris@14 345 #
Chris@14 346 # @return [boolean, string] name of the layout to use or false for no layout
Chris@14 347 def use_layout
Chris@14 348 request.xhr? ? false : 'base'
Chris@14 349 end
Chris@441 350
Chris@0 351 def invalid_authenticity_token
Chris@0 352 if api_request?
Chris@0 353 logger.error "Form authenticity token is missing or is invalid. API calls must include a proper Content-type header (text/xml or text/json)."
Chris@0 354 end
Chris@79 355 render_error "Invalid form authenticity token. Perhaps your session has timed out; try reloading the form and entering your details again."
Chris@0 356 end
Chris@441 357
Chris@441 358 def render_feed(items, options={})
Chris@0 359 @items = items || []
Chris@0 360 @items.sort! {|x,y| y.event_datetime <=> x.event_datetime }
Chris@0 361 @items = @items.slice(0, Setting.feeds_limit.to_i)
Chris@0 362 @title = options[:title] || Setting.app_title
Chris@909 363 render :template => "common/feed.atom", :layout => false,
Chris@909 364 :content_type => 'application/atom+xml'
Chris@0 365 end
Chris@909 366
Chris@507 367 # TODO: remove in Redmine 1.4
Chris@0 368 def self.accept_key_auth(*actions)
Chris@507 369 ActiveSupport::Deprecation.warn "ApplicationController.accept_key_auth is deprecated and will be removed in Redmine 1.4. Use accept_rss_auth (or accept_api_auth) instead."
Chris@507 370 accept_rss_auth(*actions)
Chris@0 371 end
Chris@441 372
Chris@507 373 # TODO: remove in Redmine 1.4
Chris@0 374 def accept_key_auth_actions
Chris@507 375 ActiveSupport::Deprecation.warn "ApplicationController.accept_key_auth_actions is deprecated and will be removed in Redmine 1.4. Use accept_rss_auth (or accept_api_auth) instead."
Chris@507 376 self.class.accept_rss_auth
Chris@507 377 end
Chris@909 378
Chris@507 379 def self.accept_rss_auth(*actions)
Chris@507 380 if actions.any?
Chris@507 381 write_inheritable_attribute('accept_rss_auth_actions', actions)
Chris@507 382 else
Chris@507 383 read_inheritable_attribute('accept_rss_auth_actions') || []
Chris@507 384 end
Chris@507 385 end
Chris@909 386
Chris@507 387 def accept_rss_auth?(action=action_name)
Chris@507 388 self.class.accept_rss_auth.include?(action.to_sym)
Chris@507 389 end
Chris@909 390
Chris@507 391 def self.accept_api_auth(*actions)
Chris@507 392 if actions.any?
Chris@507 393 write_inheritable_attribute('accept_api_auth_actions', actions)
Chris@507 394 else
Chris@507 395 read_inheritable_attribute('accept_api_auth_actions') || []
Chris@507 396 end
Chris@507 397 end
Chris@909 398
Chris@507 399 def accept_api_auth?(action=action_name)
Chris@507 400 self.class.accept_api_auth.include?(action.to_sym)
Chris@0 401 end
Chris@441 402
Chris@0 403 # Returns the number of objects that should be displayed
Chris@0 404 # on the paginated list
Chris@0 405 def per_page_option
Chris@0 406 per_page = nil
Chris@0 407 if params[:per_page] && Setting.per_page_options_array.include?(params[:per_page].to_s.to_i)
Chris@0 408 per_page = params[:per_page].to_s.to_i
Chris@0 409 session[:per_page] = per_page
Chris@0 410 elsif session[:per_page]
Chris@0 411 per_page = session[:per_page]
Chris@0 412 else
Chris@0 413 per_page = Setting.per_page_options_array.first || 25
Chris@0 414 end
Chris@0 415 per_page
Chris@0 416 end
Chris@0 417
Chris@117 418 # Returns offset and limit used to retrieve objects
Chris@117 419 # for an API response based on offset, limit and page parameters
Chris@117 420 def api_offset_and_limit(options=params)
Chris@117 421 if options[:offset].present?
Chris@117 422 offset = options[:offset].to_i
Chris@117 423 if offset < 0
Chris@117 424 offset = 0
Chris@117 425 end
Chris@117 426 end
Chris@117 427 limit = options[:limit].to_i
Chris@117 428 if limit < 1
Chris@117 429 limit = 25
Chris@117 430 elsif limit > 100
Chris@117 431 limit = 100
Chris@117 432 end
Chris@117 433 if offset.nil? && options[:page].present?
Chris@117 434 offset = (options[:page].to_i - 1) * limit
Chris@117 435 offset = 0 if offset < 0
Chris@117 436 end
Chris@117 437 offset ||= 0
Chris@441 438
Chris@117 439 [offset, limit]
Chris@117 440 end
Chris@441 441
Chris@0 442 # qvalues http header parser
Chris@0 443 # code taken from webrick
Chris@0 444 def parse_qvalues(value)
Chris@0 445 tmp = []
Chris@0 446 if value
Chris@0 447 parts = value.split(/,\s*/)
Chris@0 448 parts.each {|part|
Chris@0 449 if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
Chris@0 450 val = m[1]
Chris@0 451 q = (m[2] or 1).to_f
Chris@0 452 tmp.push([val, q])
Chris@0 453 end
Chris@0 454 }
Chris@0 455 tmp = tmp.sort_by{|val, q| -q}
Chris@0 456 tmp.collect!{|val, q| val}
Chris@0 457 end
Chris@0 458 return tmp
Chris@0 459 rescue
Chris@0 460 nil
Chris@0 461 end
Chris@441 462
Chris@0 463 # Returns a string that can be used as filename value in Content-Disposition header
Chris@0 464 def filename_for_content_disposition(name)
Chris@0 465 request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
Chris@0 466 end
Chris@441 467
Chris@0 468 def api_request?
Chris@0 469 %w(xml json).include? params[:format]
Chris@0 470 end
Chris@441 471
Chris@117 472 # Returns the API key present in the request
Chris@117 473 def api_key_from_request
Chris@117 474 if params[:key].present?
Chris@117 475 params[:key]
Chris@117 476 elsif request.headers["X-Redmine-API-Key"].present?
Chris@117 477 request.headers["X-Redmine-API-Key"]
Chris@117 478 end
Chris@117 479 end
Chris@0 480
Chris@0 481 # Renders a warning flash if obj has unsaved attachments
Chris@0 482 def render_attachment_warning_if_needed(obj)
Chris@0 483 flash[:warning] = l(:warning_attachments_not_saved, obj.unsaved_attachments.size) if obj.unsaved_attachments.present?
Chris@0 484 end
Chris@0 485
Chris@14 486 # Sets the `flash` notice or error based the number of issues that did not save
Chris@14 487 #
Chris@14 488 # @param [Array, Issue] issues all of the saved and unsaved Issues
Chris@14 489 # @param [Array, Integer] unsaved_issue_ids the issue ids that were not saved
Chris@14 490 def set_flash_from_bulk_issue_save(issues, unsaved_issue_ids)
Chris@14 491 if unsaved_issue_ids.empty?
Chris@14 492 flash[:notice] = l(:notice_successful_update) unless issues.empty?
Chris@14 493 else
Chris@14 494 flash[:error] = l(:notice_failed_to_save_issues,
Chris@14 495 :count => unsaved_issue_ids.size,
Chris@14 496 :total => issues.size,
Chris@14 497 :ids => '#' + unsaved_issue_ids.join(', #'))
Chris@14 498 end
Chris@14 499 end
Chris@14 500
Chris@0 501 # Rescues an invalid query statement. Just in case...
Chris@0 502 def query_statement_invalid(exception)
Chris@0 503 logger.error "Query::StatementInvalid: #{exception.message}" if logger
Chris@0 504 session.delete(:query)
Chris@0 505 sort_clear if respond_to?(:sort_clear)
Chris@0 506 render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator."
Chris@0 507 end
Chris@0 508
Chris@117 509 # Renders API response on validation failure
Chris@117 510 def render_validation_errors(object)
Chris@117 511 options = { :status => :unprocessable_entity, :layout => false }
Chris@117 512 options.merge!(case params[:format]
Chris@117 513 when 'xml'; { :xml => object.errors }
Chris@117 514 when 'json'; { :json => {'errors' => object.errors} } # ActiveResource client compliance
Chris@117 515 else
Chris@117 516 raise "Unknown format #{params[:format]} in #render_validation_errors"
Chris@117 517 end
Chris@117 518 )
Chris@117 519 render options
Chris@117 520 end
Chris@441 521
Chris@117 522 # Overrides #default_template so that the api template
Chris@117 523 # is used automatically if it exists
Chris@117 524 def default_template(action_name = self.action_name)
Chris@117 525 if api_request?
Chris@117 526 begin
Chris@117 527 return self.view_paths.find_template(default_template_name(action_name), 'api')
Chris@117 528 rescue ::ActionView::MissingTemplate
Chris@117 529 # the api template was not found
Chris@117 530 # fallback to the default behaviour
Chris@117 531 end
Chris@117 532 end
Chris@117 533 super
Chris@117 534 end
Chris@441 535
Chris@117 536 # Overrides #pick_layout so that #render with no arguments
Chris@117 537 # doesn't use the layout for api requests
Chris@117 538 def pick_layout(*args)
Chris@117 539 api_request? ? nil : super
Chris@117 540 end
Chris@0 541 end