Just to be educated I wanted to know if it is a good practice to have one controller method for both GET and POST actions, e.g def signup ... end, which would display a form and if request.post? is true – then perform all the business-logic and so on. Is it any good approach, or should I have these methods being separated from each other ?
Thanks in advice!
There is little difference in code organisation either way.
With separate methods, it looks like:
With the same method, it looks like:
It looks like they are both reasonably well organised. Choose what your prefer. If they are the default CRUD methods, separate methods are nice, given that there are separate names thought up already (eg.
newvscreate,editvsupdate).If they are not CRUD, or extra forms on the page, and you can only think of one name for it (like
signup), feel free to overload the name and use the same method.