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

112 views
Skip to first unread message

Roelof Wobben

unread,
Aug 13, 2014, 2:20:14 AM8/13/14
to rubyonra...@googlegroups.com
Hello,

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.

Roelof

BuyzLots

unread,
Aug 13, 2014, 2:26:52 AM8/13/14
to rubyonra...@googlegroups.com
you could use current_page with route to check the page.  Ex:
render “sidebar” unless current_page?(login_path)

Matt
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fc9ab3e6-e2ee-4417-adab-653d4f210fa5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roelof Wobben

unread,
Aug 13, 2014, 2:32:48 AM8/13/14
to rubyonra...@googlegroups.com
oke , and put this in the controller ??

Roelof


Op woensdag 13 augustus 2014 08:26:52 UTC+2 schreef matt:

Eric Saupe

unread,
Aug 13, 2014, 11:56:23 AM8/13/14
to rubyonra...@googlegroups.com
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) %>


Roelof Wobben

unread,
Aug 13, 2014, 2:24:27 PM8/13/14
to rubyonra...@googlegroups.com
Sorry but I do not work.  I see a message that login_path is not known. I think that devise is messing things  up.

Roelof

Op woensdag 13 augustus 2014 17:56:23 UTC+2 schreef Eric Saupe:

Germano Teixeira

unread,
Aug 13, 2014, 3:08:52 PM8/13/14
to rubyonra...@googlegroups.com
You have to look in your routes file what is your login_path.
login_path is just a example.


Germano Teixeira

unread,
Aug 13, 2014, 3:09:30 PM8/13/14
to rubyonra...@googlegroups.com
run "rake routes" in cosole to see your login path.

Roelof Wobben

unread,
Aug 13, 2014, 3:20:26 PM8/13/14
to rubyonra...@googlegroups.com
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.

Roelof


Op woensdag 13 augustus 2014 21:09:30 UTC+2 schreef Germano Teixeira:

Eric Saupe

unread,
Aug 13, 2014, 4:06:47 PM8/13/14
to rubyonra...@googlegroups.com
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) %>

Roelof Wobben

unread,
Aug 14, 2014, 2:16:05 AM8/14/14
to rubyonra...@googlegroups.com
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.

Roelof



Op woensdag 13 augustus 2014 22:06:47 UTC+2 schreef Eric Saupe:

James Davis, PhD

unread,
Aug 14, 2014, 7:54:36 AM8/14/14
to rubyonra...@googlegroups.com
Add the folder name where your sidebar partial is located.

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

Roelof Wobben

unread,
Aug 14, 2014, 9:10:21 AM8/14/14
to rubyonra...@googlegroups.com
undefined local variable or method `“layouts' for #<#<Class:0x007f50394a0340>:0x007f503949ded8>

Roelof


Op donderdag 14 augustus 2014 13:54:36 UTC+2 schreef James Davis, PhD:

Colin Law

unread,
Aug 14, 2014, 9:56:33 AM8/14/14
to rubyonra...@googlegroups.com
On 14 August 2014 14:10, Roelof Wobben <rwo...@hotmail.com> wrote:
> undefined local variable or method `“layouts' for
> #<#<Class:0x007f50394a0340>:0x007f503949ded8>

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

Colin
> https://groups.google.com/d/msgid/rubyonrails-talk/105043fb-b0ad-4551-b54f-6a8df16c2f19%40googlegroups.com.

Roelof Wobben

unread,
Aug 14, 2014, 11:21:27 AM8/14/14
to rubyonra...@googlegroups.com
Here is the whole layout :

<!DOCTYPE html>
<html lang="en">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Liberator Admin Theme</title>
 <link rel="apple-touch-icon" sizes="144x144" href="apple-touch-icon-ipad-retina.png" />
 <link rel="apple-touch-icon" sizes="114x114" href="apple-touch-icon-iphone-retina.png" />
 <link rel="apple-touch-icon" sizes="72x72" href="apple-touch-icon-ipad.png" />
 <link rel="apple-touch-icon" sizes="57x57" href="apple-touch-icon-iphone.png" />
 <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
 <!-- bootstrap -->
 
     <%= stylesheet_link_tag "bootstrap/bootstrap.css", "font-awesome-4.0.3/css/font-awesome.min.css", "jquery-ui.css", "toastr.css", "style.css" %>
    
</head>
<body>
  <%= render “layouts/sidebar” unless current_page?(new_admin_session_path) %>
</body>
</html>

The sidebar.html.erb can be found here : http://pastebin.com/4HJ69Pa7

Roelof

Op donderdag 14 augustus 2014 15:56:33 UTC+2 schreef Colin Law:

Colin Law

unread,
Aug 14, 2014, 11:52:25 AM8/14/14
to rubyonra...@googlegroups.com
On 14 August 2014 16:21, Roelof Wobben <rwo...@hotmail.com> wrote:
> Here is the whole layout :

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

Colin

Roelof Wobben

unread,
Aug 14, 2014, 1:10:51 PM8/14/14
to rubyonra...@googlegroups.com
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>):                                                                             
    18: </head>                                                                                                                                                                                            
    19: <body>                                                                                                                                                                                             
    20:                                                                                                                                                                                                    
    21:          <%= render “layouts/sidebar” unless current_page?(new_admin_session_path) %>                                                                                                              
    22:                                                                                                                                                                                                    
    23: </body>                                                                                                                                                                                            
    24: </html>                                                                                                                                                                                            
  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

Roelof



Op donderdag 14 augustus 2014 17:52:25 UTC+2 schreef Colin Law:

Hassan Schroeder

unread,
Aug 14, 2014, 1:19:36 PM8/14/14
to rubyonrails-talk
On Thu, Aug 14, 2014 at 10:10 AM, Roelof Wobben <rwo...@hotmail.com> wrote:

> ActionView::Template::Error (undefined local variable or method `“layouts'
> for #<#<Class:0x007f6269e4a548>:0x007f6269e49080>):
> 21: <%= render “layouts/sidebar” unless
> current_page?(new_admin_session_path) %>
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.

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

Roelof Wobben

unread,
Aug 14, 2014, 3:01:23 PM8/14/14
to rubyonra...@googlegroups.com
Thanks,,

Im using the ide of nitrious.io 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.

Roelof


Op donderdag 14 augustus 2014 19:19:36 UTC+2 schreef Hassan Schroeder:

Colin Law

unread,
Aug 14, 2014, 3:23:22 PM8/14/14
to rubyonra...@googlegroups.com
On 14 August 2014 18:18, Hassan Schroeder <hassan.s...@gmail.com> wrote:
> On Thu, Aug 14, 2014 at 10:10 AM, Roelof Wobben <rwo...@hotmail.com> wrote:
>
>> ActionView::Template::Error (undefined local variable or method `“layouts'
>> for #<#<Class:0x007f6269e4a548>:0x007f6269e49080>):
>> 21: <%= render “layouts/sidebar” unless
>> current_page?(new_admin_session_path) %>
> 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.

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

Colin
Reply all
Reply to author
Forward
0 new messages