I have a primary layout that I''m using in several controllers. On my sidebar I have a link that I set up as follows: <div id="sidebar"> <%= link_to("Items", :action => "list") %> </div> Everything is ok when I call it from my primary controller, but since I am also calling the layout from a second controller that does not have list defined I am getting an error. What I''d like to do is make the action => "list" absolute so that it goes to action => controller "primary" =>"list" Is there any way to do that? Or else do I just have to define list a second time in the second controller? -- Posted via http://www.ruby-forum.com/.
Why don''t you add a :controller option to the link like so: <div id="sidebar"> <%= link_to("Items", :controller => ''primary'', :action => "list") %> </div> Kent. On Sunday 11 December 2005 22:06, Vince W. wrote:> I have a primary layout that I''m using in several controllers. On my > sidebar I have a link that I set up as follows: > > <div id="sidebar"> > <%= link_to("Items", :action => "list") %> > </div> > > Everything is ok when I call it from my primary controller, but since I > am also calling the layout from a second controller that does not have > list defined I am getting an error. > > What I''d like to do is make the action => "list" absolute so that it > goes to action => controller "primary" =>"list" > > Is there any way to do that? Or else do I just have to define list a > second time in the second controller?
Vince, The way that I''ve gotten around this one is to use something like <%= link_to("Items", :action => "/list") %> That way your always calling the right action. Alternatively you could use <%= link_to("Items", :controller=>"Item", :action => "list" %> but I think you still need to put the / in there. Cheers On 12/12/05, Vince W. <vince71-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have a primary layout that I''m using in several controllers. On my > sidebar I have a link that I set up as follows: > > <div id="sidebar"> > <%= link_to("Items", :action => "list") %> > </div> > > Everything is ok when I call it from my primary controller, but since I > am also calling the layout from a second controller that does not have > list defined I am getting an error. > > What I''d like to do is make the action => "list" absolute so that it > goes to action => controller "primary" =>"list" > > Is there any way to do that? Or else do I just have to define list a > second time in the second controller? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
There are a few ways to make shared components like this work. One was already mentioned in that you could just specify a certain controller on the link_to. You could also define sidebar as a shared component which would live at app>views>shared and include it where you''d like via <%= render(:partial => "shared/sidebar") %>. Additionally, you could make it a component in the components directory (same level as app). A good start info-wise is here: http://wiki.rubyonrails.com/rails/pages/Components. You''ll still need to specify what controller / action you want in each of the sidebar links, but this follows the DRY principal quite nicely by locating the sidebar in one location. On Dec 11, 2005, at 9:06 PM, Vince W. wrote:> I have a primary layout that I''m using in several controllers. On my > sidebar I have a link that I set up as follows: > > <div id="sidebar"> > <%= link_to("Items", :action => "list") %> > </div> > > Everything is ok when I call it from my primary controller, but > since I > am also calling the layout from a second controller that does not have > list defined I am getting an error. > > What I''d like to do is make the action => "list" absolute so that it > goes to action => controller "primary" =>"list" > > Is there any way to do that? Or else do I just have to define list a > second time in the second controller? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
On Monday 12 Dec 2005 03:06, Vince W. wrote:> Everything is ok when I call it from my primary controller, but since I > am also calling the layout from a second controller that does not have > list defined I am getting an error. > What I''d like to do is make the action => "list" absolute so that it > goes to action => controller "primary" =>"list" > Is there any way to do that? Or else do I just have to define list a > second time in the second controller?Perhaps just make it conditional in your layout (change the name to the one where you don''t want it visible, assuming it should be visible in all others): <% unless controller.controller_name == "the_one_where_you_want_it_hidden" -%> <div id="sidebar"> <%= link_to("Items", :action => "list") %> </div> <% end -%> Or alternatively, if you only want to show it in the primary one (again, change the name to whatever the only one you do want it visible is): <% if controller.controller_name == "primary" -%> <div id="sidebar"> <%= link_to("Items", :action => "list") %> </div> <% end -%> Untested, but either should do what you want. HTH! :-) ~Dave -- Dave Silvester Rent-A-Monkey Website Development Web: http://www.rentamonkey.com/
Kent, I''ve found in some circumstances say a User controller, and an Admin::User controller, that rails can get confused. since the User and Admin::User are really both User Controllers. That''s why I''ve added the extra / in the action. On 12/12/05, Kent Sibilev <ksruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Why don''t you add a :controller option to the link like so: > > <div id="sidebar"> > <%= link_to("Items", :controller => ''primary'', :action => "list") %> > </div> > > Kent. > > On Sunday 11 December 2005 22:06, Vince W. wrote: > > I have a primary layout that I''m using in several controllers. On my > > sidebar I have a link that I set up as follows: > > > > <div id="sidebar"> > > <%= link_to("Items", :action => "list") %> > > </div> > > > > Everything is ok when I call it from my primary controller, but since I > > am also calling the layout from a second controller that does not have > > list defined I am getting an error. > > > > What I''d like to do is make the action => "list" absolute so that it > > goes to action => controller "primary" =>"list" > > > > Is there any way to do that? Or else do I just have to define list a > > second time in the second controller? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Isn''t it that this extra / should be added to the controller name, not action name? Kent. On Sunday 11 December 2005 23:25, Liquid wrote:> Kent, > > I''ve found in some circumstances say a User controller, and an Admin::User > controller, > that rails can get confused. since the User and Admin::User are really > both User Controllers. That''s why I''ve added the extra / in the action. > > On 12/12/05, Kent Sibilev <ksruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Why don''t you add a :controller option to the link like so: > > > > <div id="sidebar"> > > <%= link_to("Items", :controller => ''primary'', :action => "list") %> > > </div> > > > > Kent. > > > > On Sunday 11 December 2005 22:06, Vince W. wrote: > > > I have a primary layout that I''m using in several controllers. On my > > > sidebar I have a link that I set up as follows: > > > > > > <div id="sidebar"> > > > <%= link_to("Items", :action => "list") %> > > > </div> > > > > > > Everything is ok when I call it from my primary controller, but since I > > > am also calling the layout from a second controller that does not have > > > list defined I am getting an error. > > > > > > What I''d like to do is make the action => "list" absolute so that it > > > goes to action => controller "primary" =>"list" > > > > > > Is there any way to do that? Or else do I just have to define list a > > > second time in the second controller? > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails
Possibly... I was typing from memory while I''m at work. Sorri if I''ve lead anyone down the garden path... Cheers On 12/12/05, Kent Sibilev <ksruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Isn''t it that this extra / should be added to the controller name, not > action > name? > > Kent. > > On Sunday 11 December 2005 23:25, Liquid wrote: > > Kent, > > > > I''ve found in some circumstances say a User controller, and an > Admin::User > > controller, > > that rails can get confused. since the User and Admin::User are really > > both User Controllers. That''s why I''ve added the extra / in the action. > > > > On 12/12/05, Kent Sibilev <ksruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Why don''t you add a :controller option to the link like so: > > > > > > <div id="sidebar"> > > > <%= link_to("Items", :controller => ''primary'', :action => "list") > %> > > > </div> > > > > > > Kent. > > > > > > On Sunday 11 December 2005 22:06, Vince W. wrote: > > > > I have a primary layout that I''m using in several controllers. On > my > > > > sidebar I have a link that I set up as follows: > > > > > > > > <div id="sidebar"> > > > > <%= link_to("Items", :action => "list") %> > > > > </div> > > > > > > > > Everything is ok when I call it from my primary controller, but > since I > > > > am also calling the layout from a second controller that does not > have > > > > list defined I am getting an error. > > > > > > > > What I''d like to do is make the action => "list" absolute so that it > > > > goes to action => controller "primary" =>"list" > > > > > > > > Is there any way to do that? Or else do I just have to define list > a > > > > second time in the second controller? > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails