Rails 3: Adding paths to routes for a new controller?

I created a new controller for one of my models called Review and named it review_controller, I injected show and update methods into it, but I can not get them to work because the rails did not add paths for the two methods.

I tried to put the following file in the routes file: match "/review/update/:id", :to => "review#update"

But this gives me ActiveRecord::RecordNotFound (Couldn't find Review with ID=update): app/controllers/review_controller.rb:16:in `update'

How can I add the path to the routes file to force my update and show the methods?

thanks

+4
source share
1 answer

For the new controller in Rails 3, you can let Rails create routes for you as follows:

 resources :review, :only => [:show, :update] 

And then, if you have to run rake routes in the terminal, you will see:

 review GET /review/:id(.:format) {:action=>"show", :controller=>"review"} PUT /review/:id(.:format) {:action=>"update", :controller=>"review"} 
+2
source

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


All Articles