The routing issue in Rails 3: ActionController :: RoutingError (No route matches ...)

I created a custom RESTful action called "post". It appears in TransactionsController as a (public) method called post.

resources :transactions do member :post do post :post end end 

I have a form configured as follows:

 <form action="/transactions/25/post"> ... <input id="transaction_submit" commit="commit" type="submit" value="Post"> </form> 

When I click the Publish button, my server receives:

 POST "/transactions/25/post" 

I expect this to call the "post" method in my TransactionController, but instead I get a routing error

 ActionController::RoutingError (No route matches "/transactions/25/post"): 

Any ideas? Thanks.

James

+4
source share
1 answer

finally found a solution, the problem is that form_for adds a hidden _method field with a value of "put" , because it's good that the transaction already exists, to circumvent this problem, I had to do the following:

 <%= form_for @transaction, :url => post_transaction_path(@transaction), :html => { :method => :post } do |form| %> 

at least this solved the problem for me, see https://rails.lighthouseapp.com/projects/8994/tickets/4884-routing-error-for-restful-resource-under-namespace for further reference

+8
source

Source: https://habr.com/ru/post/1334975/


All Articles