I''m new to RoR and the tutorials I''ve found on the web, while helpful, aren''t as "complete" as I''d like them. I understand the basics when it comes to layouts and routes, but I''m trying to get them to work together. MY first task was to implement a user authentication system (registration/login/logout/change_password). This works fine with my User controller/model/views. Now, I''ve made a default layout that resembles the following: [header] [menubar] [toolbar][main content] [footer] I made another controller called main that i am rendering into the main content part of my layout. I''ve added a route to go to main/ index when at my url, so it''s the default page. The layout HTML looks like this: <html> ..... <body> .... <div id="menubar"> <%= yield :menubar %> ... <div id="main"> <%= yield %> ... Now in my views/main/index.rhtml I have: ... <% content_for :menubar do %> <% link_to "Login", :controller => "user", :action => "Login" %> <% end %> This works great and puts the link into the menubar div. Only problem now is that when i click it the site goes to /user/Login and I lose my layout. Is there something I should be putting in my login function in my user class? Or is there another route I should have? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
in ApplicationController, for setting the layout across the site: layout ''layout_name'' That can be overridden in any of your controllers as needed: http://api.rubyonrails.org/classes/ActionController/Layout/ClassMethods.html#M000129 Jason On 5/9/07, Reacher <brandon.g.jones-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I''m new to RoR and the tutorials I''ve found on the web, while helpful, > aren''t as "complete" as I''d like them. I understand the basics when > it comes to layouts and routes, but I''m trying to get them to work > together. > > MY first task was to implement a user authentication system > (registration/login/logout/change_password). This works fine with my > User controller/model/views. Now, I''ve made a default layout that > resembles the following: > > [header] > [menubar] > [toolbar][main content] > [footer] > > I made another controller called main that i am rendering into the > main content part of my layout. I''ve added a route to go to main/ > index when at my url, so it''s the default page. The layout HTML looks > like this: > > <html> > ..... > <body> > .... > <div id="menubar"> > <%= yield :menubar %> > ... > <div id="main"> > <%= yield %> > ... > > Now in my views/main/index.rhtml I have: > > ... > <% content_for :menubar do %> > <% link_to "Login", :controller => "user", :action => "Login" %> > <% end %> > > This works great and puts the link into the menubar div. Only problem > now is that when i click it the site goes to /user/Login and I lose my > layout. Is there something I should be putting in my login function > in my user class? Or is there another route I should have? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If you mean adding a layout line to my user controller, i already did. i think it may be the path to my stylesheet because when i click the link then view the source of the page, the layout is all there but it''s not being rendered (as if it can''t see the stylesheet). my stylesheet is in public/stylesheets/default.css and the link in the layout is: <link rel="stylesheet" type="text/css" href="stylesheets/default.css" />On May 9, 11:35 am, "Jason Roelofs" <jameskil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> in ApplicationController, for setting the layout across the site: > > layout ''layout_name'' > > That can be overridden in any of your controllers as needed: > > http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho... > > Jason > > On 5/9/07, Reacher <brandon.g.jo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''m new to RoR and the tutorials I''ve found on the web, while helpful, > > aren''t as "complete" as I''d like them. I understand the basics when > > it comes to layouts and routes, but I''m trying to get them to work > > together. > > > MY first task was to implement a user authentication system > > (registration/login/logout/change_password). This works fine with my > > User controller/model/views. Now, I''ve made a default layout that > > resembles the following: > > > [header] > > [menubar] > > [toolbar][main content] > > [footer] > > > I made another controller called main that i am rendering into the > > main content part of my layout. I''ve added a route to go to main/ > > index when at my url, so it''s the default page. The layout HTML looks > > like this: > > > <html> > > ..... > > <body> > > .... > > <div id="menubar"> > > <%= yield :menubar %> > > ... > > <div id="main"> > > <%= yield %> > > ... > > > Now in my views/main/index.rhtml I have: > > > ... > > <% content_for :menubar do %> > > <% link_to "Login", :controller => "user", :action => "Login" %> > > <% end %> > > > This works great and puts the link into the menubar div. Only problem > > now is that when i click it the site goes to /user/Login and I lose my > > layout. Is there something I should be putting in my login function > > in my user class? Or is there another route I should have?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It''s "/stylesheets" And to be safe, use the stylesheet_link_tag helper instead of writing it out yourself. Jason On 5/9/07, Reacher <brandon.g.jones-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > If you mean adding a layout line to my user controller, i already > did. i think it may be the path to my stylesheet because when i click > the link then view the source of the page, the layout is all there but > it''s not being rendered (as if it can''t see the stylesheet). my > stylesheet is in public/stylesheets/default.css and the link in the > layout is: > > <link rel="stylesheet" type="text/css" href="stylesheets/default.css" / > > > > On May 9, 11:35 am, "Jason Roelofs" <jameskil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > in ApplicationController, for setting the layout across the site: > > > > layout ''layout_name'' > > > > That can be overridden in any of your controllers as needed: > > > > http://api.rubyonrails.org/classes/ActionController/Layout/ClassMetho... > > > > Jason > > > > On 5/9/07, Reacher <brandon.g.jo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > I''m new to RoR and the tutorials I''ve found on the web, while helpful, > > > aren''t as "complete" as I''d like them. I understand the basics when > > > it comes to layouts and routes, but I''m trying to get them to work > > > together. > > > > > MY first task was to implement a user authentication system > > > (registration/login/logout/change_password). This works fine with my > > > User controller/model/views. Now, I''ve made a default layout that > > > resembles the following: > > > > > [header] > > > [menubar] > > > [toolbar][main content] > > > [footer] > > > > > I made another controller called main that i am rendering into the > > > main content part of my layout. I''ve added a route to go to main/ > > > index when at my url, so it''s the default page. The layout HTML looks > > > like this: > > > > > <html> > > > ..... > > > <body> > > > .... > > > <div id="menubar"> > > > <%= yield :menubar %> > > > ... > > > <div id="main"> > > > <%= yield %> > > > ... > > > > > Now in my views/main/index.rhtml I have: > > > > > ... > > > <% content_for :menubar do %> > > > <% link_to "Login", :controller => "user", :action => "Login" %> > > > <% end %> > > > > > This works great and puts the link into the menubar div. Only problem > > > now is that when i click it the site goes to /user/Login and I lose my > > > layout. Is there something I should be putting in my login function > > > in my user class? Or is there another route I should have? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason Roelofs wrote:> It''s "/stylesheets" > > And to be safe, use the stylesheet_link_tag helper instead of writing it > out > yourself. > > JasonThis man is correct. It needs to starts with a slash so the browser can find it easily. Or just do: <%= stylesheet_link_tag ''default'' %> Also if you name your layout "application.rhtml" it will automatically be used accross all controllers unless you tell it otherwise. This is usually the approach I take. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I would take a different approach. 1) use application.rhtml for your main layout, and don''t specify another layout in any controller as long as you dont want a controller to have a totally different layout. And as your layout is just the basic skeleton, i dont think you will... 2) if your menubar will be about the same for every controller, i wouldn''t use content_for, but just put the menubar in a partial and render that in the layout. Put it in a subfolder of your views directory called e.g. "shared": <div id="menubar"> <%= render :partial => "shared/menubar" %> </div> (unsure weither you need the underscore (_menubar) when giving a path to a partial, try it out) But another common problem is, that you might want to show an entirely different menu, or e.g. a Box under the toolbar that shows the latest posts, but only in the ForumsController... here''s what you would do then: #application.rhtml (....here''s your toolbar code...) <div id="latest_posts" <%= yield :latest_posts %> </div> #forums.rhtml <% content_for :latest posts do %> (fill in code/HTML here) <% end %> <%= render :file => "layouts/application.rhtml" whats happening here is the following: If an action in ForumsController is called, rails will not render layouts/ application.rhtml, but layouts/forums.rhtml ... in this layout, you only fill the content_for :latest_posts, and then render :file the "real" layout in application.rhtml in appplication.rhtml, your :latest_posts will then be put in place. If you would call an action from another controller, forums.rhtml would not be rendered, but application.rhtml directly. so no latest_posts ;) i know this sounds weird, read this blog post, it helped me a lot: http://errtheblog.com/post/28 On 9 Mai, 19:19, Alex Wayne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Jason Roelofs wrote: > > It''s "/stylesheets" > > > And to be safe, use the stylesheet_link_tag helper instead of writing it > > out > > yourself. > > > Jason > > This man is correct. It needs to starts with a slash so the browser can > find it easily. Or just do: > > <%= stylesheet_link_tag ''default'' %> > > Also if you name your layout "application.rhtml" it will automatically > be used accross all controllers unless you tell it otherwise. This is > usually the approach I take. > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---