gpt4 book ai didi

ruby-on-rails - PG::错误:错误:关系 "users"不存在

转载 作者:行者123 更新时间:2023-11-28 19:39:47 25 4
gpt4 key购买 nike

很抱歉打扰你,但我对这个错误有很多疑问。首先这是我的 user_controller rspec 文件

需要'spec/spec_helper'

describe UserController do

it "create new user" do
post "create"
assigns[:users].should_not be_new_record
end
end

这是我的用户 Controller

 class UserController < ApplicationController
def create
@users = User.new
if @users.save
flash[:notice] = 'new user was successfully created.'
else
render :action => :new
end
end

def new
@user = User.new
end
end

和我的 routes.rb(我认为问题出在这里,对不起,我是这门语言的新手)

Estaciones::Application.routes.draw do
devise_for :users

root :to => "home#index"
resources :user
end

当我尝试测试我的 user_controller_rspec 然后我得到这个错误

失败:

1) UserController create new user
Failure/Error: post "create"
ActiveRecord::StatementInvalid:
PG::Error: ERROR: relation "users" does not exist
LINE 4: WHERE a.attrelid = '"users"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
# ./app/controllers/user_controller.rb:3:in `new'
# ./app/controllers/user_controller.rb:3:in `create'
# ./spec/controllers/user_controller_spec.rb:6

Finished in 0.01722 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/controllers/user_controller_spec.rb:5 # UserController create new user

我该如何解决...谢谢

最佳答案

运行这个

 rake db:migrate

然后这个

 rake db:test:prepare

关于ruby-on-rails - PG::错误:错误:关系 "users"不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11529738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com