简体   繁体   English

启动新的用户会话时,生产适配器导轨出现500错误

[英]500 Error in production adapter rails when starting new user session

I have been having this issue ever since I deployed and i can't figure it out. 自从部署以来,我一直都遇到这个问题,我无法解决。

I'll give some information and let me know if you need anything else! 我会提供一些信息,让我知道您是否还有其他需要! Thanks! 谢谢!

I, [2013-09-08T12:44:31.935143 #19456]  INFO -- : Started POST "/sessions" for {IP ADDRESS} at 2013-09-08 12:44:31 -0700
I, [2013-09-08T12:44:31.937969 #19456]  INFO -- : Processing by SessionsController#create as HTML
I, [2013-09-08T12:44:31.938102 #19456]  INFO -- :   Parameters: {"utf8"=>"✓", "authenticity_token"=>"{AUTHENTICITY TOKEN}", "email"=>"mike@test.com", "password"=>"[FILTERED]", "commit"=>"Log In"}
I, [2013-09-08T12:44:31.941064 #19456]  INFO -- : Completed 500 Internal Server Error in 3ms
F, [2013-09-08T12:44:31.943631 #19456] FATAL -- : 
ActiveRecord::StatementInvalid (Could not find table 'users'):
app/controllers/sessions_controller.rb:6:in `create'

Obviously it's telling me that the "users" table doesn't exist, but that BS, because it does. 显然,这是在告诉我“ users”表不存在,但该BS是存在的,因为它存在。 Perhaps it can't find the table? 也许找不到桌子? Which i ALSO think is wierd, because I created the table using Rails migrations. 我也认为这很奇怪,因为我使用Rails迁移创建了表。

Here is my production Adapter just for reference: 这是我的生产适配器,仅供参考:

production:
  adapter: mysql
  database: {DATABASENAME}
  username: {USERNAME}
  password: {PASSWORD}
  host: localhost
  port: 3306

Here is my seeds file: 这是我的种子文件:

User.create([{ email: 'mike@test2.com' }, { password_digest: 'password' }])

And my user model: 而我的用户模型:

class User < ActiveRecord::Base
  has_secure_password

  validates_uniqueness_of :email
end

And my sessions controller (handles the login): 和我的会话控制器(处理登录):

class SessionsController < ApplicationController
  def new
  end

  def create
    user = User.find_by_email(params[:email])
    if user && user.authenticate(params[:password])
      session[:user_id] = user.id
      redirect_to root_url, notice: "Logged in!"
    else
      flash.now.alert = "Email or password is invalid"
      render "new"
    end
  end

  def destroy
    session[:user_id] = nil
    redirect_to root_url, notice: "Logged out!"
  end
end

I created the user directly in the database, so the issue isn't that the user doesnt exist, the log file is saying the table 'users' doesnt exist, but that is false as well...i really don't know whats going on... 我直接在数据库中创建了用户,所以问题不在于该用户不存在,日志文件说该表“ users”不存在,但这也是错误的……我真的不知道这是什么。继续...

OH, BTW this all works in development. 哦,顺便说一句,这一切都在开发中。 Login, user creation, everything. 登录,用户创建,一切。 I was using sqlite3 for development and switched to mysql for production, just screwed everything up.... 我正在使用sqlite3进行开发,并切换到mysql进行生产,只是搞砸了所有...。

Any help is appreciated! 任何帮助表示赞赏!

For future reference, this is the fix if anyone else is having an issue with their seeds not working: 供以后参考,如果其他任何人遇到其种子无法正常工作的问题,则可以通过以下方法解决:

This is what I was using: 这是我正在使用的:

User.create([{ email: 'mike@test2.com' }, { password_digest: 'password' }])

This is what it should be: 这是应该的:

users =User.create!(:email 'mike@test2.com', :password 'password', :password_confirmation 'password')

users.save

Using 使用

Create! 

instead of just plain 而不是简单

Create 

enables validation, and the seed will fail and explain the problem. 启用验证,种子将失败并解释问题。 In my case, it was that I was using password_digest, which is the column name, instead of password and password_confirmation. 就我而言,是我使用的是password_digest(这是列名),而不是password和password_confirmation。

Also, save the seed creation in a variable (users in my case), then save said variable by doing this: 同样,将种子创建保存在变量中(在我的情况下为用户),然后通过执行以下操作保存所述变量:

users.save 

Simple as that! 就那么简单!

Hope this helps a fellow newbie in the future! 希望这对以后的新手有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM