Q: In Rails how we can decide different layout for different function in the controller?

Let us assume inside our controller we have 3 functions main_page, combined_search, vender_page  now we want different layout for every function you can achieve it by Hint below:

layout 'user', : only => [:main_page] ,:except => [:admin_page,:vender_page]
layout 'admin_layout', : only => [:admin_page],:except => [:main_page,:vender_page]
  def main_page
  render :layout => 'user'

  def vender_page

  def admin_page
    render :layout => 'admin_layout'

Hope it will solve the purpose.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: