Uninitialized constant error in controller when deploy to heroku
I try to set up devise and omniauth by follow https://github.com/plataform开发者_Go百科atec/devise/wiki/OmniAuth:-Overview and deploy to heroku. There is no error in localhost , but when I push to heroku , the app crash. In heroku logs , i found the 'uninitialized constant Users' error in omniauth_callbacks_controller.rb . How do I initialize the Users? I have heroku rake db:migrate already. But I cant run heroku console because app crash , so i cant check is there a User model.
For your information , I generate the controller by rails g omniauth_callbacks_controller
In heroku logs
/disk1/home/slugs/338566_ad6243a_bbb1-19eae435-d901-44ba-9dd5-baf36d656448/mnt/app/controllers/omniauth_callbacks_controller.rb:1: uninitialized constant Users (NameError)
In omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.facebook_data"] = env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
Are you sure the User model has been created in Heroku's database?
In your terminal (NOT the rails console!) enter
heroku rake db:migrate
That will migrate Heroku's DB's to match your code. Do you then still have the error?
Heroku needs to migrate with model, so you need to run
heroku rake db:migrate
then refresh your page, now its working :)
精彩评论