没有路由匹配{:action =>“ show”,:controller =>“ user”,:id => nil} [英] No route matches {:action=>"show", :controller=>"user", :id=>nil}

查看:98
本文介绍了没有路由匹配{:action =>“ show”,:controller =>“ user”,:id => nil}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有这个问题(帖子标题)。

Hello everybody, I have this problem (title of the post).

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测试

And here is my rspec test

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


推荐答案

if @user.save
   redirect_to :action => :show, :id => @user.id
else
 ...
end

这篇关于没有路由匹配{:action =&gt;“ show”,:controller =&gt;“ user”,:id =&gt; nil}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆