Rails combining RESTful methods in a new controlle

2019-07-13 06:23发布

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?

3条回答
做自己的国王
2楼-- · 2019-07-13 06:54

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楼-- · 2019-07-13 07:05

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.

查看更多
姐就是有狂的资本
4楼-- · 2019-07-13 07:06

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.

查看更多
登录 后发表回答