Pregunta

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. Perhaps it can't find the table? Which i ALSO think is wierd, because I created the table using Rails migrations.

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...

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....

Any help is appreciated!

¿Fue útil?

Solución

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.

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!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top