我不知道该怎么做才能解决这个错误。只要按“创建帐户”,我就会收到一条错误消息,说找不到表'帐户'。ActiveRecord :: StatementInvalid AccountsController#new
class AccountsController < ApplicationController
def new
@account = Account.new
end
def create
@account = Account.new(account_params)
if @account.save
redirect_to root_path, notice: 'Signed up successfully'
else
render action: 'new'
end
end
private
def account_params
params.require(:account).permit(:subdomain)
end
end
错误
ActiveRecord::StatementInvalid (Could not find table 'accounts'):
app/controllers/accounts_controller.rb:4:in `new
找不到表 '账户'
Started GET "/accounts/new" for 127.0.0.1 at 2015-01-06 13:19:40 -0500
Processing by AccountsController#new as HTML
Completed 500 Internal Server Error in 4ms
ActiveRecord::StatementInvalid (Could not find table 'accounts'):
app/controllers/accounts_controller.rb:4:in `new'
Rendered /home/shuabe/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0/lib/action_dispatch
/templates/rescues/_source.erb (10.1ms)
Rendered /home/shuabe/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0/lib/action_dispatch
/templates/rescues/_trace.html.erb (4.3ms)
Rendered /home/shuabe/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0/lib/action_dispatch
/templates/rescues/_request_and_response.html.erb (1.3ms)
Rendered /home/shuabe/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0/lib/action_dispatch
/templates/rescues/_web_console.html.erb (1.6ms)
Rendered /home/shuabe/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0/lib/action_dispatch
/templates/rescues/diagnostics.html.erb within rescues/layout (51.2ms)
Started GET "/accounts/new" for 127.0.0.1 at 2015-01-06 13:19:41 -0500
Processing by AccountsController#new as HTML
Completed 500 Internal Server Error in 1ms
ActiveRecord::StatementInvalid (Could not find table 'accounts'):
app/controllers/accounts_controller.rb:4:in `new'
Rendered /home/shuabe/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0/lib/action_dispatch
/templates/rescues/_source.erb (9.7ms)
Rendered /home/shuabe/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0/lib/action_dispatch
/templates/rescues/_trace.html.erb (4.0ms)
Rendered /home/shuabe/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0/lib/action_dispatch
/templates/rescues/_request_and_response.html.erb (1.3ms)
Rendered /home/shuabe/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0/lib/action_dispatch
/templates/rescues/_web_console.html.erb (1.4ms)
Rendered /home/shuabe/.rvm/gems/ruby-2.1.5/gems/web-console-2.0.0/lib/action_dispatch
/templates/rescues/diagnostics.html.erb within rescues/layout (38.4ms)
我不知道,但它有什么关系迁移?我没有产生任何迁移。如果是迁移,我如何为账户控制器生成表格?
我不是目前使用的设计和我使用的唯一的宝石:基于您的评论
gem 'factory_girl_rails', '~> 4.5.0'
gem 'rails', '4.2.0'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
gem 'spring'
检查你的数据库,你真的有一个名为'accounts'的表吗?在rails中,如果你使用其中一个生成器创建你的模型(例如'rails g model Account'),那么你就可以进行迁移。如果您手动创建模型,那么您已经为自己做了一些额外的工作,并且需要[自己创建迁移](http://stackoverflow.com/a/14452094/877472)。 –
您是否创建帐户模型?你是否迁移了数据库rake db:migrate? –
@RailsOuter如果他们忘记迁移,他们实际上会得到一个不同的错误(通常是说“等待迁移”)。 –