Hi, Basically I''m just wondering how I can change my link_to''s location slightly. At the moment I have a system with categories and tutorials, and the categories have_many tutorials. The link itself is like this: <%= link_to ''Next lesson'', @NextLesson, :controller => ''categories'', :id => (@category.id), :action => (@NextLesson) %> I''ve set the controller etc because my routes.rb file handles the routes like this: map.connect ''categories/:id/tutorials/:action'', :controller => ''categories'' So from this I figures the link would lead to: /categories/ID/ tutorials/ID however it doesn''t, it just leads to: /tutorials/ID Does anyone know how I can change it from /tutorials/TUTID to / categories/CATID/tutorials/TUTID ? Thanks In Advance, Joe -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Assuming you''re using REST (far better, IMO), although your map.connect would make me think otherwise... map.resources :tutorials, :controller => "categories" :path_prefix => "/category/:category_id", :name_prefix => "category_" should yield /categories/category.id/tutorials/tutorial.id and category_tutorial as a named route, with a link something like this: <%= link_to ''Next lesson'', category_tutorial_path(:category_id => @category.id, :id => @NextLesson) %> I think, although your @NextLesson seems bizarre. If that doesn''t work, have you done a "rake routes >routes.lst" then looked at your routes.lst to see what routing you actually have? Rails will match the first route it finds given the inputs in the specified order. http://api.rubyonrails.org/classes/ActionController/Resources.html -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Adding your section into routes.rb seems to give me this error on attempting to run the server: unexpected tASSOC, expecting kEND On May 10, 7:58 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Assuming you''re using REST (far better, IMO), although your map.connect > would make me think otherwise... > > map.resources :tutorials, > :controller => "categories" > :path_prefix => "/category/:category_id", > :name_prefix => "category_" > > should yield /categories/category.id/tutorials/tutorial.id > and category_tutorial as a named route, with a link something like this: > > <%= link_to ''Next lesson'', > category_tutorial_path(:category_id => @category.id, > :id => @NextLesson) %> > > I think, although your @NextLesson seems bizarre. > > If that doesn''t work, have you done a "rake routes >routes.lst" > then looked at your routes.lst to see what routing you actually have? > Rails will match the first route it finds given the inputs in the > specified order. > > http://api.rubyonrails.org/classes/ActionController/Resources.html > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
(dont know why the last post posted, I wasn''t done yet) Please note the last error was for the path:prefix line. Also on your route list thing it gives me this error (about the colon next to the path_prefix line): unexpected '','' expecting kEND (The server running also mentions then '','' but not in as much details. This means it wont let me rake the routes or whatever to see the routes. Please Help, Thanks In Advance, Joe On May 11, 7:18 am, Joe <j...-T/oTI28FLjDQXOPxS62xeg@public.gmane.org> wrote:> Adding your section into routes.rb seems to give me this error on > attempting to run the server: > > unexpected tASSOC, expecting kEND > > On May 10, 7:58 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > > > Assuming you''re using REST (far better, IMO), although your map.connect > > would make me think otherwise... > > > map.resources :tutorials, > > :controller => "categories" > > :path_prefix => "/category/:category_id", > > :name_prefix => "category_" > > > should yield /categories/category.id/tutorials/tutorial.id > > and category_tutorial as a named route, with a link something like this: > > > <%= link_to ''Next lesson'', > > category_tutorial_path(:category_id => @category.id, > > :id => @NextLesson) %> > > > I think, although your @NextLesson seems bizarre. > > > If that doesn''t work, have you done a "rake routes >routes.lst" > > then looked at your routes.lst to see what routing you actually have? > > Rails will match the first route it finds given the inputs in the > > specified order. > > >http://api.rubyonrails.org/classes/ActionController/Resources.html > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
map.resources :tutorials, :controller => "categories" :path_prefix => "/category/:category_id", There should be a comma at the end of the second line after "categories", my bad. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
youtube-T/oTI28FLjDQXOPxS62xeg@public.gmane.org
2010-May-11 16:19 UTC
Re: Changing link_to link location slightly..
THANK YOU SO MUCH! On May 11, 4:54 pm, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> map.resources :tutorials, > :controller => "categories" > :path_prefix => "/category/:category_id", > > There should be a comma at the end of the second line after > "categories", my bad. > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.