We have answer of your question!

100% solved queries, no empty question

Question: Best Practice for Dual Layouts in Rails 3


0

I have a rails 3 application that has 2 distinct layouts. One is for the end users, and the other is an admin console for managing the application.

That is usually very easy to handle since I can define a controller to use 1 layout. This works fine for most settings since they do not involve the end user. But some of my models will. For example an admin editing a user profile vs a user. To make this work should I have duplicate controllers for a model? One for the admin console and one for the users? Seems like I have thrown DRY out the window.

Thanks in advance for any feedback.

Question author Bdubbs | Source

Answer


1


It seems to me an admin might be doing different things with a user than an end user would be doing so different controllers may not be completely unDRY.

However, if they are completely the same and you just want to have a different layout, then you can just set your layout based on the current user. Something like this would work:

layout :determine_layout

def determine_layout
  return 'admin' if current_user && current_user.admin?
  'application'
end
Answer author Alex-peachey

Tickanswer.com is providing the only single recommended solution of the question Best Practice for Dual Layouts in Rails 3 under the categories i.e ruby-on-rails , ruby , ruby-on-rails-3 , . Our team of experts filter the best solution for you.

Related Search Queries:


You may also add your answer

Thanks for contributing an answer to Tick Answer!