开发者

How to modify a link?

开发者 https://www.devze.com 2023-01-27 18:30 出处:网络
I need to modify this link to go to channels/params[:channel_id]/messages here is the current link <%= link_to pluralize(@channel.messages.size, \'message\') %>

I need to modify this link to go to

channels/params[:channel_id]/messages

here is the current link

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

result of rake routes

{:action=>"index", :controller=>"messages"}  POST   /channels/:channel_id/messages(.:format)         
{:action=>"create", :co开发者_StackOverflowntroller=>"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)     


If you would have used nested routes and if you redirect that link to index action in messages controller, then you can define your link like this:

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


You don't really need to "modify" it, since it most likely never worked anyway :)

Search for the path macro for your route, using:

rake routes

Then you can use the correct macro, which most likely is something like channel_message. You'll reach something like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号