Routing Error with Rails 3 with Members

I have the following route in rails 3:

resources :jobs do 
    member do 
      post :seller_job_submitted
    end
  end

And the next view

=form_for job, :url=>seller_job_submitted_job_path(job), :remote=>true do |f|

I know this is not very reassuring, but right now it's just a break. Anyway, I get this error when submitting the form

Started POST "/jobs/74/seller_job_submitted" for 127.0.0.1    
ActionController::RoutingError (No route matches "/jobs/74/seller_job_submitted"):

but when I run rake routes | grep seller_job_submitted, I think the correct results will return:

seller_job_submitted_job POST   /jobs/:id/seller_job_submitted(.:format)                  {:action=>"seller_job_submitted", :controller=>"jobs"}

Any ideas on what could happen?

Thank!

+3
source share
3 answers

Assuming you have defined a seller_job_submitted method in the model and controller. Change the code to

resources :jobs    
match "jobs/:id/seller_job_submitted" => "jobs#seller_job_submitted", :as => "seller_job_submitted"

Then in the form_for tag use :url=>seller_job_submitted_path

This should fix your problem: you did not explicitly specify seller_job_submitted_job_path.

0
source

, put post? :post .

, , , REST ( ).

, , Rails - post URL-, put.

0

, Rails 3. , POST . Rb.

resources :jobs do
   member do
   post :seller_job_submitted # will not work
   put  :seller_job_submitted # will just work
end

, FORM POST.

0

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


All Articles