Reputation: 3573
I would like to give my application 2 different views (HTML, CSS, JS):
and make possible for the authorized user to switch between them.
As for now I have 2nd and I'm going to create user authorization (probably with CanCan gem) and then 1st.
guides.rubyonrails.org "2.2.12.2 Choosing Layouts at Runtime" describes nice way to switch between layouts but it's not enough for me I think.
In my case both layouts would look the same or almost the same:
<!DOCTYPE html>
<html>
<head>
# layout depended JS and CSS maybe
</head>
<body class="container">
<%= render 'layouts/navbar' %>
<%= render 'layouts/flash' %>
<%= yield %>
</body>
</html>
What I'm interested in is to decide somehow which folder will be used to fill yield
above.
I have slides_controller.rb and /app/views/slides/* and I would like to create one more, let say /app/views/slides_nice/* and use same slides_controller to decide which one should be used for rendering.
Upvotes: 0
Views: 1555
Reputation: 1087
I think what you need is to authenticate in controller and give different template to render.
such as (assuming there is current_user helper from devise or your own authentication solusion):
if current_user
render "template_1"
else
render "template_2"
Also CanCan is currently outdated as R Bates no longer updating it. It does not work with new rails releases. And i'm not sure if role based authorization is what you want, you seems just want to hide something from guest users.
Upvotes: 1