“visit named_route_path”抛出ArgumentError

时间:2013-03-13 18:25:15

标签: ruby-on-rails ruby rspec

我在Rails 3.1.12应用程序中设置了此路由:

  get '/compte/activer/:username/:token' => 'create_user#activate', :as => :create_user_activate

这是请求规范:

describe "#activate with valid token" do
  it "activates the account" do    
    user = User.create_basic("conradk", "email@email.com", "Conrad K.", "password", "password", "Hello world!")

    visit create_user_activate_path(:username => user.username, :token => user.activation_token)

    page.should have_content(I18n.t('activerecord.success.messages.account_activated'))
  end
end

这是控制器:

class CreateUserController < ApplicationController
  def activate username, token

  end
end

当我运行规范时,我收到此错误:

Failure/Error: visit create_user_activate_path(:username => user.username, :token => user.activation_token)
     ArgumentError:
       wrong number of arguments (0 for 2)

我做错了什么?

2 个答案:

答案 0 :(得分:2)

试试这个

class CreateUserController < ApplicationController
  def activate

  end
end

答案 1 :(得分:2)

您的控制器方法应定义如下:

class CreateUserController < ApplicationController
  def activate
    #params will have your username and token
    user_name = params[:username]
    token = params[:token]
  end
end