添加新的行动路线

use*_*826 15 ruby routes ruby-on-rails

我在用户控制器中获得了这些操作

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
Run Code Online (Sandbox Code Playgroud)

我希望能够通过 /users/another_new某种链接:method => :another_create 进行调用/users/another_new

我得到了以下config/routes.rb

get '/users/another_new' :to => 'users#another_new'
resources :users
Run Code Online (Sandbox Code Playgroud)

我的问题是,如果这是添加的正确方法get以及我如何添加another_create方法.

Ket*_*ukh 27

在你的config/routes.rb文件中执行此操作

resources :users do
  collection do
    get 'another_new'
    post 'another_create'
  end
end
Run Code Online (Sandbox Code Playgroud)

还可以看一下这里对概念的清晰理解.

希望这能帮助你老兄:)