Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it wrong to not implement all REST actions in Rails controller?

Let's say I have a SessionsController, which controls user login and logout, but the only actions I really need are new (for displaying login form), create (for authentication and login) and destroy for logging out the user.

Is there any problem if I just have these three actions in my controller, or do I have to implement them all to make it correctly RESTful?

And second little question. Some people say that scaffolding is bad, and that one should write code by hand, but I find it pretty useful and time saving.

Is it OK to use scaffolding, or is it evil that should be avoided and why?

like image 706
Jakub Arnold Avatar asked Dec 07 '22 06:12

Jakub Arnold


1 Answers

It is definitely okay to only create the RESTful actions which you want to support for that resource. You do not have to define all 7 actions. In fact, the majority of my controllers do not use all 7 actions.

Is it OK to use scaffolding, or is it evil that should be avoided and why?

The built-in Rails scaffolding is mainly designed to help get off the ground when beginning. I personally don't use it for everyday development for a few reasons.

  • it generates a CSS and layout file when I want to use the existing application one
  • it generates all controller actions (like I said I usually don't want all of them)
  • it creates an XML format for every action which I almost never want
  • it does not put the form in a partial when I need both "edit" and "new" actions
  • I sometimes use a different testing library (such as Shoulda or RSpec)

However, I am a fan of scaffolding for speeding up development. This is why I created the nifty_scaffold generator which I use almost all the time. It does not have the problems mentioned above.

like image 167
ryanb Avatar answered Jan 11 '23 01:01

ryanb