Hi,
In my rails application I have a controller (message) that handles all
top-level directory requests, and maps it to a list view.
How can I use link_to to link to the URLs generated by this route?
map.connect '':forum_url_name/'', :controller =>
''messages'', :action => ''list''
Then I have a (forum) controller that lists all its record on its list
action. Currently this is what I do:
<%= link_to forum.name, ''/'' + forum.url_name %>
Obviously that''s not pretty, since it''s half hard-coded... I
don''t know
if I''m making sense, so here are the relevant files (snippets):
messages_controller.rb:
def list
@forum = Forum.find(:all, :conditions => [''url_name =
?'',
params[:forum_url_name]])
if @forum.empty?
render_text "404: Not found"
else
for f in @forum
@forum_id = f.id
end
@messages = Message.find(:all, :conditions => ["parent_id IS NULL
AND forum_id = ?", @forum.id])
end
end
views/forums/list.rhtml:
<% for forum in @forums %>
<li><%= link_to forum.name, ''/'' + forum.url_name
%></li>
<% end %>
routes.rb:
map.connect '''', :controller =>
''forums'', :action => ''list''
map.connect '':forum_url_name/'', :controller =>
''messages'', :action =>
''list''
map.connect ''/nuevo/:forum_url_name/'', :controller =>
''messages'',
:action => ''new''
Notice that last connection. If I do this (inside a messages controller
view):
<%= link_to ''New message'', :action =>
''new'' %>
The links get magically created like so: "/nuevo/support/" (for
example). How is this magic worked?
Thanks in advance!
Ivan V.