大家好,我有这个问题(帖子的标题)。
Failure/Error: get :create, :user => { :email => 'foo@example.com', :name => 'userexample' }
ActionController::RoutingError:No route matches {:action=>"show", :controller=>"user", :id=>nil}
这是我的UserController
。
class UserController < ApplicationController
def new
end
def create
@user = User.new(params[:user])
@user.save
redirect_to :action => :show, :id => @user.id
end
def show
@user = User.find(params[:id])
end
end
这是我的路线.rb
::Application.routes.draw do
devise_for :users
root :to => "user#index"
resources :user
#match "newuser" => "user#new"
get "user/new"
post "user/create"
get "user/:id" => "user#show"
这是我的 rspec 测试
require 'spec/spec_helper'
describe UserController do
it "create new user" do
get :create, :user => { :email => 'foo@example.com', :name => 'userexample' }
flash[:notice] = 'new user was successfully created.'
end
end
end