我做的Hartl的教程和我的Rails应用程序的开发工作正常,但在崩溃的Heroku此错误代码:Heroku的应用程序崩溃错误:未初始化不断的ApplicationController :: SessionsHelper(NameError)
application_controller.rb:5:in `<class:ApplicationController>': uninitialized constant ApplicationController::SessionsHelper (NameError)
这发生在我为模式添加remember_digest后发生。不知道是否是迁移或
的ApplicationController SessionHelper和ApplicationController中之间的问题
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include SessionsHelper
end
Sessions_Helper.rb
module SessionsHelper
# Logs in the given user.
def log_in(user)
session[:user_id] = user.id
end
# Remembers a user in a persistent session.
def remember(user)
user.remember
cookies.permanent.signed[:user_id] = user.id
cookies.permanent[:remember_token] = user.remember_token
end
# Returns the user corresponding to the remember token cookie.
def current_user
if (user_id = session[:user_id])
@current_user ||= User.find_by(id: user_id)
elsif (user_id = cookies.signed[:user_id])
user = User.find_by(id: user_id)
if user && user.authenticated?(cookies[:remember_token])
log_in user
@current_user = user
end
end
end
# Returns true if the user is logged in, false otherwise.
def logged_in?
!current_user.nil?
end
def forget(user)
user.forget
cookies.delete(:user_id)
cookies.delete(:remember_token)
end
# Logs out the current user.
def log_out
forget(current_user)
session.delete(:user_id)
@current_user = nil
end
end
我想删除我的老Heroku的应用并开始一个新的重置迁移(在过去一直努力“排除故障”),但这次并没有奏效。当我运行heroku rake db:migrate
时,除了记住的摘要之外,所有的迁移都显示出来。我跑db:再次迁移但不能迁移。下面是迁移:
Migrate.db
20150204074511_create_users.rb 20150204093042_add_phone_number_to_users.rb
20150204081616_add_index_to_users_email.rb 20150204094519_add_index_to_users_phone_number.rb
20150204081750_add_password_digest_to_users.rb 20150207093225_add_remember_digest_to_users.rb
迁移日志
[email protected]:~/workspace/AccessOBD (master) $ heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.4474
(18.0ms) CREATE TABLE "schema_migrations" ("version" character varying NOT NULL)
(8.6ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
ActiveRecord::SchemaMigration Load (1.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
Migrating to CreateUsers (20150204074511)
(0.9ms) BEGIN
== 20150204074511 CreateUsers: migrating ======================================
-- create_table(:users)
(15.1ms) CREATE TABLE "users" ("id" serial primary key, "name" character varying, "email" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
-> 0.0162s
== 20150204074511 CreateUsers: migrated (0.0164s) =============================
SQL (1.2ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20150204074511"]]
(4.0ms) COMMIT
Migrating to AddIndexToUsersEmail (20150204081616)
(0.8ms) BEGIN
== 20150204081616 AddIndexToUsersEmail: migrating =============================
-- add_index(:users, :email, {:unique=>true})
(4.6ms) CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email")
-> 0.0081s
== 20150204081616 AddIndexToUsersEmail: migrated (0.0082s) ====================
SQL (0.9ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20150204081616"]]
(5.5ms) COMMIT
Migrating to AddPasswordDigestToUsers (20150204081750)
(0.7ms) BEGIN
== 20150204081750 AddPasswordDigestToUsers: migrating =========================
-- add_column(:users, :password_digest, :string)
(1.3ms) ALTER TABLE "users" ADD "password_digest" character varying
-> 0.0022s
== 20150204081750 AddPasswordDigestToUsers: migrated (0.0023s) ================
SQL (0.8ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20150204081750"]]
(1.7ms) COMMIT
Migrating to AddPhoneNumberToUsers (20150204093042)
(0.7ms) BEGIN
== 20150204093042 AddPhoneNumberToUsers: migrating ============================
-- add_column(:users, :phone, :string)
(1.4ms) ALTER TABLE "users" ADD "phone" character varying
-> 0.0023s
== 20150204093042 AddPhoneNumberToUsers: migrated (0.0024s) ===================
SQL (0.9ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20150204093042"]]
(2.8ms) COMMIT
Migrating to AddIndexToUsersPhoneNumber (20150204094519)
(4.4ms) BEGIN
== 20150204094519 AddIndexToUsersPhoneNumber: migrating =======================
-- add_index(:users, :phone, {:unique=>true})
(7.5ms) CREATE UNIQUE INDEX "index_users_on_phone" ON "users" ("phone")
-> 0.0110s
== 20150204094519 AddIndexToUsersPhoneNumber: migrated (0.0111s) ==============
SQL (0.8ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20150204094519"]]
(4.7ms) COMMIT
我怎样才能得到这最后的迁移工作?
你可以包含'''sessions_helper.rb'''文件的顶部吗? – garythegoat 2015-02-08 21:59:07
@garythegoat没问题,它的第二个文件包含在上面 – 2015-02-09 03:54:58
您是否指的是应用程序控制器文件?我要求的是sessions_helper.rb文件的完整代码。您错过了应该包含在顶部的模块定义。 – garythegoat 2015-02-09 04:01:48