Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing problem in Rails 3: ActionController::RoutingError (No route matches ...)

I've 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've got a form configured as follows:

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

When I hit the "Post" button, my server receives:

POST "/transactions/25/post"

I expect this to call the "post" method in my TransactionController but instead I'm getting a routing error

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

Any ideas? Thanks.

James

like image 681
James Roscoe Avatar asked Feb 26 '23 10:02

James Roscoe


1 Answers

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

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

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

like image 170
lwe Avatar answered Mar 05 '23 19:03

lwe