Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I avoid creating a full RESTful CRUD resource if I only Create/Read?

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.

like image 930
mevqz Avatar asked Dec 12 '25 05:12

mevqz


1 Answers

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!

like image 163
Gavin Miller Avatar answered Dec 14 '25 03:12

Gavin Miller