kranz
kranz

Reputation: 621

Conditionally render partials in application layout

In a Rails 3 application layout i include a partial for flash messages. While this is ok in most cases, there is a view where I would need flash messages appear in another place; is there a way in layouts/application.html.erb to say something like

<%= render 'layout/messages' unless somecondition %>

where somecondition is something able to detect that I am in 'myview/index'?

Upvotes: 0

Views: 533

Answers (1)

Gavin Miller
Gavin Miller

Reputation: 43825

Sure is, use params[:controller] and params[:action] actually you should use controller_name and action_name per the Rails documentation

<%= render 'layout/messages' 
  if controller_name == 'myview' && action_name == 'index' %>

Upvotes: 5

Related Questions