]> git.openstreetmap.org Git - rails.git/commitdiff
Another approach, but this time without scattering stuff all over the methods
authorAndy Allan <andy@gravitystorm.co.uk>
Thu, 27 Jan 2011 17:55:36 +0000 (17:55 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 3 Apr 2011 12:46:17 +0000 (13:46 +0100)
app/controllers/user_controller.rb

index 3d20120647cc1f6fb4a45ef49d0f6542a8c66cdd..ed17c1e41ea04e32f32c7e47fe235bce83637659 100644 (file)
@@ -1,5 +1,5 @@
 class UserController < ApplicationController
 class UserController < ApplicationController
-  layout 'site', :except => [:api_details]
+  layout :choose_layout
 
   before_filter :authorize, :only => [:api_details, :api_gpx_files]
   before_filter :authorize_web, :except => [:api_details, :api_gpx_files]
 
   before_filter :authorize, :only => [:api_details, :api_gpx_files]
   before_filter :authorize_web, :except => [:api_details, :api_gpx_files]
@@ -257,7 +257,6 @@ class UserController < ApplicationController
     elsif flash[:notice].nil?
       flash.now[:notice] =  t 'user.login.notice'
     end
     elsif flash[:notice].nil?
       flash.now[:notice] =  t 'user.login.notice'
     end
-    render :layout => 'slim'
   end
 
   def logout
   end
 
   def logout
@@ -497,4 +496,17 @@ private
   rescue ActiveRecord::RecordNotFound
     redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name] unless @this_user
   end
   rescue ActiveRecord::RecordNotFound
     redirect_to :controller => 'user', :action => 'view', :display_name => params[:display_name] unless @this_user
   end
+
+  ##
+  # Choose the layout to use. See
+  # https://rails.lighthouseapp.com/projects/8994/tickets/5371-layout-with-onlyexcept-options-makes-other-actions-render-without-layouts
+  def choose_layout
+    if [ 'api_details' ].include? action_name
+      nil
+    elsif [ 'login', 'new', 'terms'].include? action_name
+      'slim'
+    else
+      'site'
+    end
+  end
 end
 end