Rails combining RESTful methods in a new controller

僤鯓⒐⒋嵵緔 提交于 2019-12-13 16:06:51

问题


I have a rails app where users create projects. Currently these are nested, and are completed as separate actions (A user registers, and then from the project dashboard creates a new project).

To improve conversions (as well as track conversions from adwords and facebook) I want to create a new view called getting_started whereby a user will register and create a project in one step from a single view.

In terms of best practice, should I create a new controller for this, rather than just slapping a new view in users?


回答1:


I 'm not very experienced in this field but as far as I worked,

To create a new controller for a single function, i.e getting_started which is 100% related to an existing controller doesn't make sense. I 'll advise to place in the existing controller.

If we talk about efficiency, these will take exactly same time.




回答2:


In my opinion better way is create another controller. Then you have better atomization of code. Which is easier to refactor. You can inherit this controller, and use super for creating user.




回答3:


You can think of getting_started as an alternative to users#new, so you could add it as a new action to UsersController and add another action to respond to the POST and create a user with a nested project (I'm assuming you are filling in some form and that you are accepting nested attributes in your User model).

No need to create a new controller and inherit from it in my opinion.



来源:https://stackoverflow.com/questions/39996290/rails-combining-restful-methods-in-a-new-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!