I know that this is a really dumb question but I am just starting with Ruby on Rails (4) and web development: Suppose that I am making a simple web application that manages Articles. The articles can be Created or Read but it cannot be Deleted or Updated. How would be the correct approach to achieve this? By only deleting the corresponding actions in the controller or by replacing (in the config/routes.rb) the "resources :articles" by specifics "matchs" statements?
Thanks in advance, any suggestion would be greatly appreciated.
You're most of the way there. Delete the actions in the controller, and restrict the actions in the routes like this:
resources :article, only: [:create, :show, :index]
You can also use except to filter the resources as well.
resources :article, except: [:delete, :update]
Stick with RESTful routing where you can, especially when your code naturally follows that pattern. You'll find if you follow Rails conventions you'll be a much happier developer, and hit fewer WTF framework moments!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With