我在用户 Controller 中得到了这些 Action
class UsersController < ApplicationController
def index #default action
...
end
def new #default action
...
end
def another_new
...
end
def create
...
end
def another_create
...
end
end
我希望能够
/users/another_new
并从某种链接调用 :method => :another_create
使 /users/another_new
我得到了以下 config/routes.rb
get '/users/another_new' :to => 'users#another_new'
resources :users
我的问题是这是否是添加 get
的正确方法以及我如何添加 another_create 方法。
最佳答案
在你的 config/routes.rb 文件中这样做
resources :users do
collection do
get 'another_new'
post 'another_create'
end
end
也看看HERE以便清楚地理解概念。
希望这对你有帮助老兄:)
关于ruby-on-rails - 向路由添加新操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13498981/