如何修改链接?

时间:2010-11-30 04:27:36

标签: ruby-on-rails

我需要修改此链接转到

channels/params[:channel_id]/messages

这是当前链接

<%= link_to pluralize(@channel.messages.size, 'message') %>

佣金路线的结果

{:action=>"index", :controller=>"messages"}  POST   /channels/:channel_id/messages(.:format)         
{:action=>"create", :controller=>"messages"}new_channel_message GET    /channels/:channel_id/messages/new(.:format)      
{:action=>"new", :controller=>"messages"} edit_channel_message GET    /channels/:channel_id/messages/:id/edit(.:format) 
{:action=>"edit", :controller=>"messages"}channel_message GET    /channels/:channel_id/messages/:id(.:format)      
{:action=>"show", :controller=>"messages"} PUT    /channels/:channel_id/messages/:id(.:format)      
{:action=>"update", :controller=>"messages"} DELETE /channels/:channel_id/messages/:id(.:format)     
{:action=>"destroy", :controller=>"messages"} channels GET    /channels(.:format)                              
{:action=>"index", :controller=>"channels"} POST   /channels(.:format)                              
{:action=>"create", :controller=>"channels"}  new_channel GET    /channels/new(.:format)                          
{:action=>"new", :controller=>"channels"} edit_channel GET    /channels/:id/edit(.:format)                      
{:action=>"edit", :controller=>"channels"}channel GET    /channels/:id(.:format)                           
{:action=>"show", :controller=>"channels"}PUT    /channels/:id(.:format)                           
{:action=>"update", :controller=>"channels"} DELETE /channels/:id(.:format)     

2 个答案:

答案 0 :(得分:1)

你真的不需要“修改”它,因为它很可能永远不会工作:)

使用以下方法搜索路线的路径宏:

rake routes

然后你可以使用正确的宏,这很可能是channel_message。你会达到这样的目的:

<%= link_to pluralize(@channel.messages.size, 'message'), channel_message_path(@channel) %>

答案 1 :(得分:1)

如果您使用嵌套路由,并且将该链接重定向到消息控制器中的索引操作,那么您可以像这样定义链接:

<%= link_to pluralize(@channel.messages.size, 'message'), channel_messages_path(@channel) %>