Rails AntiPatterns: Best Practice Ruby on Rails Refactoring (Addison-Wesley Professional Ruby)

Author: Chad Pytel, Tammer Saleh
4.6
All Stack Overflow 9

Comments

by anonymous   2017-08-20

I guess that there's no real advantage at creating new actions. And from what I can remember from that book you should stick to the 7 classic actions (index / show / new / edit / create / update / delete) if you can, in order to keep everything RESTFul.

Anyway, the action would probably do the same thing.

a classic update would be :

def update
  user = User.find(params[:id]).update_attributes! params[:user]
end

and the eventual update_password & update_email would probably look something like that

def update_email
  user = User.find(params[:id]).update_attributes! email: params[:user][:email]
end

def update_password
  user = User.find(params[:id]).update_attributes! password: params[:user][:password]
end

When using a single action (the update one) , the only eventual problem would be that a user could update its password via the change email form by changing the html on the page for instance. I don't think that this is a problem as the user has the ability to change his password anyway.

So I would stick to the classic update method.

If I missed your point, please let me know ;)

by anonymous   2017-08-20

To add to all of the above, another good book after you get through those resources is Rails Antipatterns. While I do not suggest this book for a beginner as learning the basics of Rails is overwhelming enough, once you get past that stage then this book will be the logical next step in learning how to refactor your code better.