我不知道該怎麼做才能解決這個錯誤。只要按「創建帳戶」,我就會收到一條錯誤消息,說找不到表'帳戶'。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如果他們忘記遷移,他們實際上會得到一個不同的錯誤(通常是說「等待遷移」)。 –