Im making forum and i have problem with paths. Here is code: http://pastie.caboo.se/6389 With this code, it works. But its a bit weird to use so many paths function. For every path i need to make new function. So can you suggest me something. Tables are like here: http://wiki.rubyonrails.com/rails/pages/ForumExample -- Posted via http://www.ruby-forum.com/.
asdf wrote:> Im making forum and i have problem with paths. > > Here is code: > http://pastie.caboo.se/6389 > > With this code, it works. But its a bit weird to use so many paths > function. For every path i need to make new function. So can you suggest > me something. > > Tables are like here: > http://wiki.rubyonrails.com/rails/pages/ForumExampleTry using named routes, and then you can use the magic named route URL helper methods. # routes.rb: map.with_options(:controller => ''forum'') do |m| m.category ''/forum/show_category/:id'' m.forum ''/forum/show_forum/:id'' m.title ''/forum/show_title/:id'' end # show_topic.rhtml <%= link_to category_url(@list.first.forum.category) %> >> <%= link_to forum_url(@list.first.forum) %> >> <%= link_to topic_url(@list.first) %><br/> The named URL helpers act like url_for, but generate the URL using the corresponding named route. You can pass arguments that get mapped to the URL params in order, or using a hash for the mapping. -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.
... no answers? I mean like in this forum. On top there is: Ruby on Rails > Title -- Posted via http://www.ruby-forum.com/.
Ooops, I messed up the named routes. Need the :action requirement. Josh Susser wrote: # routes.rb: map.with_options(:controller => ''forum'') do |m| m.category ''/forum/show_category/:id'', :action => ''show_category'' m.forum ''/forum/show_forum/:id'', :action => ''show_forum'' m.title ''/forum/show_title/:id'', :action => ''show_title'' end -- Josh Susser http://blog.hasmanythrough.com -- Posted via http://www.ruby-forum.com/.
OT: Pastie looks very cool -- Posted via http://www.ruby-forum.com/.
Showing app/views/forum/show_topic.rhtml where line #1 raised: can''t convert ActiveRecord::Associations::BelongsToAssociation into Hash What im doing wrong? -- Posted via http://www.ruby-forum.com/.
Josh Susser wrote:> Ooops, I messed up the named routes. Need the :action requirement. > > Josh Susser wrote: > # routes.rb: > map.with_options(:controller => ''forum'') do |m| > m.category ''/forum/show_category/:id'', :action => ''show_category'' > m.forum ''/forum/show_forum/:id'', :action => ''show_forum'' > m.title ''/forum/show_title/:id'', :action => ''show_title'' > end > > -- > Josh Susser > http://blog.hasmanythrough.comHmm... I think that is not i want. If i make <%= link_to topic_url %>, ill get this: http://localhost:3000/forum/show_topic But i want path like: Category > Forum > Topic_name or i just dont know how to use ur example? -- Posted via http://www.ruby-forum.com/.
That''s called breadcrumbs. This something you are looking for? http://pastie.caboo.se/6551 On 7/29/06, asdf <innu@urgas.net> wrote:> Josh Susser wrote: > > Ooops, I messed up the named routes. Need the :action requirement. > > > > Josh Susser wrote: > > # routes.rb: > > map.with_options(:controller => ''forum'') do |m| > > m.category ''/forum/show_category/:id'', :action => ''show_category'' > > m.forum ''/forum/show_forum/:id'', :action => ''show_forum'' > > m.title ''/forum/show_title/:id'', :action => ''show_title'' > > end > > > > -- > > Josh Susser > > http://blog.hasmanythrough.com > > Hmm... I think that is not i want. > > If i make <%= link_to topic_url %>, ill get this: > http://localhost:3000/forum/show_topic > But i want path like: Category > Forum > Topic_name > or i just dont know how to use ur example? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- -------------- Jon Gretar Borgthorsson http://www.jongretar.net/
It is almoust what i wanted. But if i go to forum or category page or new topic page, i cant use same function. When im in topic page, it must show: Category_name -> Forum_name -> Topic_name If im doing new reply i need to get: Category_name -> Forum_name -> Topic_name -> New_Reply If im looking for categories i need to get: Category_name I just dont know how to do this. Im not going to put like 8 if to function? There just must be a better way... J?n Borg??rsson wrote:> That''s called breadcrumbs. > > This something you are looking for? > http://pastie.caboo.se/6551-- Posted via http://www.ruby-forum.com/.
... -- Posted via http://www.ruby-forum.com/.
bump -- Posted via http://www.ruby-forum.com/.
asdf wrote:> It is almoust what i wanted. But if i go to forum or category page or > new topic page, i cant use same function. > > When im in topic page, it must show: > Category_name -> Forum_name -> Topic_name > > If im doing new reply i need to get: > Category_name -> Forum_name -> Topic_name -> New_Reply > > If im looking for categories i need to get: > Category_name > > > I just dont know how to do this. Im not going to put like 8 if to > function? > There just must be a better way... > > J?n Borg??rsson wrote: >> That''s called breadcrumbs. >> >> This something you are looking for? >> http://pastie.caboo.se/6551I have done something similar with a system of categories, subcategories, products. It involves methods to call url_for with the proper options, and some routes Code here: http://pastie.caboo.se/6793 It allows you to do product_url(@product), which will generate: "/products/parent_cat/sub_cat/1" and category_url(@category) which gnereates: "/products/foo" or "/products/foo/bar" based on wether @category is a parent or a child. -- Posted via http://www.ruby-forum.com/.