Rails Set Layout Based on URLs

So, I'm trying to change the layout of the view based on url parameters.

So far, I realized that I need to install the layout in the controller. In my controller, under the action of the show, I have:

if params['iframe'] == 'true'
  render :layout => 'vendored'
end

The 'vendored' layout exists in views / layouts. I get scary rendering several times. Here is the rest of the show action in my controller:

 def show
    @event = Event.find(params[:id])
    @user = current_user
    @approved_employers = current_user.get_employers_approving_event(@event) if user_signed_in?
    respond_with(@event)

The problem is that I do not see another render. I do not see another in the entire controller. Of course, there is a render somewhere, because it displays my default application layout, is this the cause of the problem? I read in rail documents what I can add

and return

, , , , . redirect_to. ? ?

+4
2

. . :

  before_filter :set_layout, :only => [:show]

  private

  def set_layout
   self.class.layout ( params['iframe'] == 'true' ? 'vendored' :  'application')
  end
+3

, , :

class YourController < ApplicationController
  layout :iframe_layout

  private

  def iframe_layout
    params['iframe'] ? "vendored" : "application"
  end
end
+7

All Articles