Routes setting when press the button generated by link_to tag

When I click the link below, it goes to /messages/discard.1 instead of /messages/discard/1 . Any idea what am I doing wrong?

My View:

  <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
              messages_discard_path(@messages.id),
              :method => 'post',
              :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
              :class => 'btn btn-danger' %>

My Routes:

  match '/messages/discard' => 'messages#discard', :via => :post

Answers


Try revising the link_to method and use:

messages_discard_path(@messages)

Instead.

Also, it looks like that route is missing :id in it. I'm assuming you need match '/messages/:id/discard' => 'messages#discard', :via => :post instead.


Need Your Help

Nested Routes and Parameters for Rails URLs (Best Practice)

ruby-on-rails restful-url nested-urls

I have a decent understanding of RESTful urls and all the theory behind not nesting urls, but I'm still not quite sure how this looks in an enterprise application, like something like Amazon,

Is NodeJS a socket library for networking?

javascript c node.js sockets

Below is the server program(C) using socket functionality provided by libC