asdf
July 28, 2006, 8:51pm
1
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
asdf
July 29, 2006, 3:37pm
2
…
no answers?
I mean like in this forum. On top there is: Ruby on Rails > Title
asdf
July 29, 2006, 5:01pm
3
OT: Pastie looks very cool
asdf
July 29, 2006, 5:46pm
4
asdf wrote:
Im making forum and i have problem with paths.
Here is code:
Parked at Loopia
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:
Peak Obsession
Try 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 ) %>
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 S.
http://blog.hasmanythrough.com
asdf
July 29, 2006, 5:52pm
5
Ooops, I messed up the named routes. Need the :action requirement.
Josh S. 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 S.
http://blog.hasmanythrough.com
asdf
July 29, 2006, 11:25pm
6
Josh S. wrote:
Ooops, I messed up the named routes. Need the :action requirement.
Josh S. 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 S.
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?
asdf
July 29, 2006, 7:32pm
7
Showing app/views/forum/show_topic.rhtml where line #1 raised:
can’t convert ActiveRecord::Associations::BelongsToAssociation into Hash
What im doing wrong?
asdf
July 30, 2006, 1:49am
8
asdf
July 30, 2006, 12:47pm
9
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?
Parked at Loopia
asdf
July 31, 2006, 10:53pm
11
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?
Parked at Loopia
I 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: Parked at Loopia
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.