Forum

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


no answers?

I mean like in this forum. On top there is: Ruby on Rails > Title

OT: Pastie looks very cool

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

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

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?

Showing app/views/forum/show_topic.rhtml where line #1 raised:
can’t convert ActiveRecord::Associations::BelongsToAssociation into Hash

What im doing wrong?

That’s called breadcrumbs.

This something you are looking for?
http://pastie.caboo.se/6551

On 7/29/06, asdf [email protected] wrote:


Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

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

bump

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.