I posted about the path argument of the link_to method before, but today I was in a situation where I passed two arguments, so I will summarize it so that I will not forget it.
<% link_to 'Character to be displayed', ○○_path %>
By doing so, it can be treated like an HTML a tag.
The URI of rails routes in the terminal
/class_rooms/:class_room_id/messages/:id(.:format)
If ":" and "id" are attached, it is necessary to pass an argument there.
Requires arguments for : class_room_id
and: id
.
In the previous example,
The first : class_room_id
is needed because the routing is nested.
routes.rb
resources :class_rooms, only: [:index, :new, :create] do
resources :messages, only: [:index, :create, :destroy]
end
If the routing is nested, you must specify two path arguments for link_to. </ font>
<%= link_to 'Character to be displayed', class_room_message_path(@class_room, message) %>
The order to specify is the order in the URI.
Recommended Posts