conditional layout question ? sidebar visible on all pages except the login page.


Allmost all pages have the same layout except the login page.

There the sidebar with menu is not visible.

Is there a way to tell rails that when im on the login page the sidebar must not be visible.


you could use current_page with route to check the page. Ex:
render “sidebar” unless current_page?(login_path)


oke , and put this in the controller ??


No, the render command goes in your layout in this case since it is something that a lot of your views are using.

<%= render “sidebar” unless current_page?(login_path) %>


Sorry but I do not work. I see a message that login_path is not known. I think that devise is messing things up.


You have to look in your routes file what is your login_path.
login_path is just a example.

run “rake routes” in cosole to see your login path.

Rake routes :

Prefix Verb URI Pattern Controller#Action

new_admin_session GET /admins/sign_in(.:format) devise/sessions#new

admin_session POST /admins/sign_in(.:format) devise/sessions#create

destroy_admin_session DELETE /admins/sign_out(.:format) devise/sessions#destroy

cancel_admin_registration GET /admins/cancel(.:format) devise/registrations#cancel

admin_registration POST /admins(.:format) devise/registrations#create

new_admin_registration GET /admins/sign_up(.:format) devise/registrations#new

edit_admin_registration GET /admins/edit(.:format) devise/registrations#edit

PATCH /admins(.:format) devise/registrations#update

PUT /admins(.:format) devise/registrations#update

DELETE /admins(.:format) devise/registrations#destroy

dashboard_show GET /dashboard/show(.:format) dashboard#show

root GET / dashboard#show

I tried already new_admin_registration but then I see the same error message.


You still need _path. So in your case, since it is the login which I’m assuming is new_admin_session, it would be

<%= render “sidebar” unless current_page?(new_admin_session_path) %>

then I see this error message ;

undefined local variable or method `“sidebar”' for #<#<Class:0x007fc6a2ce9c38>:0x007fc6a50d7118>

Where I have a sidebar.html.erb and a _sidebar.html.erb in the same directory.


Add the folder name where your sidebar partial is located.

<%= render “layouts/sidebar” unless current_page?(new_admin_session_path) %>

undefined local variable or method `“layouts' for #<#<Class:0x007f50394a0340>:0x007f503949ded8>


undefined local variable or method `“layouts' for

Show us the line of code that error is generated on (with a couple of
lines each side). Copy/paste it here.


Here is the whole layout :

Liberator Admin Theme
 <%= stylesheet_link_tag "bootstrap/bootstrap.css", "font-awesome-4.0.3/css/font-awesome.min.css", "jquery-ui.css", "toastr.css", "style.css" %>

<%= render “layouts/sidebar” unless current_page?(new_admin_session_path) %>

The sidebar.html.erb can be found here :


Look at the stack trace and find which line of your code generated the
error, then post just that section.


I think you mean this :

Processing by DashboardController#show as HTML

Rendered dashboard/show.html.erb within layouts/application (2.1ms)

Rendered dashboard/show.html.erb within layouts/application (2.1ms)

Completed 500 Internal Server Error in 80ms

Completed 500 Internal Server Error in 80ms

ActionView::Template::Error (undefined local variable or method `“layouts’ for #<#Class:0x007f6269e4a548:0x007f6269e49080>):




21: <%= render “layouts/sidebar” unless current_page?(new_admin_session_path) %>




app/views/layouts/application.html.erb:21:in `_app_views_layouts_application_html_erb___4215202385565524198_70030324135900’

Or do you mean the application.stack, framework trace or the whole trace.
I see the error when doing rails s


What in the name of all that's merciful are you using as an editor?

Look *closely* at the error message.

You're using "smart" (sic) quotes instead of normal double-quote
characters. Fix that and it'll work as expected.


Im using the ide of but this is the next problem that arise with wrong characters.

I think I will look for a decent Linux distro and look then for a solution where I can have all the files at one window. my code in another and a terminal as a footer.


Well spotted Hassan. Isn't it annoying when someone sees something
that one should have seen oneself :slight_smile:
Particularly when I am always telling people to look at the error message.