[英]make a custom url for create action with RESTful routing
In Rails 4 I'm trying to make a custom root for a particular action in the users controller, so i want my restful resources for users still like they are, but change only the url for the create
action and make it to be for example /account/register
. 在Rails 4中,我试图为用户控制器中的特定操作创建自定义根目录,因此我希望为用户提供我喜欢的静态资源,但仅更改create
动作的url,例如/account/register
。 I'm trying do this as the follow but it seem not work : 我正在尝试按照以下步骤进行操作,但似乎不起作用:
resources :users, except: [:create] # first i eliminate creation of create root
resources :users, path: "account/register", as: :users, only: [:create] # then i just try to make a custom route for only create action
i want still using users_path and not change any of my routing helper in the view, please any idea ? 我想仍然使用users_path并且不更改视图中的任何路由助手,请问有什么想法吗?
How about: 怎么样:
post "/account/register" => "users#create", as: :users
This will create a route where /account/register
points to UsersController#create. 这将创建一个路由,其中/account/register
指向UsersController#create。 This can be referenced with users_path
. 可以使用users_path
来引用。
尝试:
match '/account/register' => 'user#create', via: :post
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.