- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试登录 Rails 应用程序时出现以下错误。我使用设计进行身份验证。我的错误是
设计中的 NoMethodError::SessionsController#create
未定义的方法 `current_sign_in_at'
我的用户模型是
models/user.rb
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
attr_accessible :admin,:first_name, :last_name, :profile_name, :college_name, :email, :password, :password_confirmation, :remember_me, :provider, :uid
def admin?
end
def self.find_for_facebook_oauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.email = auth.info.email
user.password = Devise.friendly_token[0,20]
#user.name = auth.info.name # assuming the user model has a name
#user.image = auth.info.image # assuming the user model has an image
user.save!
end
end
end
db/schema.rb
ActiveRecord::Schema.define(:version => 20140126101946) do
create_table "levels", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "first_name"
t.string "last_name"
t.string "profile_name"
t.string "college_name"
t.string "email", :default => "", :null => false
t.string "encrypted_password", :default => "", :null => false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "provider"
t.string "uid"
t.boolean "admin", :default => false
end
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
end
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
t.string :first_name
t.string :last_name
t.string :profile_name
t.string :college_name
## Database authenticatable
t.string :email, :null => false, :default => ""
t.string :encrypted_password, :null => false, :default => ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, :default => 0
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
最佳答案
要将新列添加到现有表中,仅更新已运行的迁移是行不通的,因为架构的版本高于现有迁移的版本。如果你想修改现有的迁移,你可以运行 down
迁移:
rake db:migrate:down VERSION=20140126101944 # use version of the user migration
up
迁移使用:
rake db:migrate:up VERSION=20140126101944 # use version of the user migration
trackable
现有列
users
table :
class AddTrackableColumnsToUser < ActiveRecord::Migration
def change
change_table :users do |t|
## Trackable
t.add_column :sign_in_count, :integer, :default => 0
t.add_column :current_sign_in_at, :datetime
t.add_column :last_sign_in_at, :datetime
t.add_column :current_sign_in_ip, :string
t.add_column :last_sign_in_ip, :string
end
end
end
db:migrate
:
rake db:migrate
关于ruby-on-rails - 设计中的 NoMethodError::SessionsController#create 未定义方法 `current_sign_in_at',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21383860/
我正在编写一个 API 并尝试使用该 API 登录并收到 uninitialized constant SessionsController 错误,然后是“尝试运行 rake 路由以获取有关可用路由的
我正在尝试覆盖 Devise 中的 destroy 方法 SessionsController ,但我还没有成功。我已经为 create 做了这件事方法,但我不知道为什么它不适用于 destroy方法
我正在尝试在我的主页上设置登录表单。我按照 Wiki 设法做到了 除了,如果登录信息不正确,/devise/session/new.html.erb被渲染。 我不想要那个。我希望我的用户被重定向到 r
使用 Devise 管理用户 session /注册我需要在每次用户登录时以及在他被设计重定向到主页以进行连接之前执行特定任务(例如更新该特定用户的用户表中的某些字段)用户。 我是否必须覆盖设计 Se
我正在尝试向 Devise 的 SessionsController 添加一个 before_destroy 过滤器。 这是我尝试过的: 我创建了一个包含 before_destroy 过滤器的模块和
我有用于使用 devise gem 进行授权的用户模型。我想添加 after_sign_in_path 方法: # application_controller.rb protected # redi
我正在尝试使用 :lockable ,所以当我将它添加到 class User Rails.root: /Users/user/Ruby Application Trace | Framework
我正在使用经过修改以启用 Active Admin 的 Ruby on Rails 5 Api 应用程序。到现在为止一切都很好。我不记得在应用程序中做过任何更改,但现在,如果我在浏览器上删除 cook
当我尝试登录 Rails 应用程序时出现以下错误。我使用设计进行身份验证。我的错误是 设计中的 NoMethodError::SessionsController#create 未定义的方法 `cur
我从这个 repo 中克隆了一个测验应用程序项目:https://github.com/Pk13055/quiz-app 我正在尝试使用以下命令从我的系统运行它: rails server 但我收到此
这可能是我没有正确处理依赖注入(inject)的问题,但我正在尝试为我的 SessionsController 提供“ session ”服务。这是我的 SessionsController: ang
我安装了 ActiveAdmin 并使用默认管理员名称和密码登录,但出现错误,希望有人能帮助我。谢谢 ! 这是错误: ArgumentError in ActiveAdmin::Devise::Ses
我正在尝试为 iPhone 应用构建一个 Rails API。 Devise 可以很好地通过 Web 界面登录,但我需要能够使用 REST API 创建和销毁 session ,我想使用 JSON 而
我尝试了很长时间,并用谷歌搜索了我无法摆脱的问题。任何人都可以解释为什么会发生这种情况以及如何解决它。 def new self.resource = resource_class.new
我在使用 Rails 3 和 Devise 时遇到了一个特殊问题。我的 Rails 应用程序有 3 种用户类型: 客户、所有者和管理员 routes.rb: devise_for :admins
蛋糕版本 3.1.2 我做了什么: 在 MySQL 数据库中运行以下查询: CREATE TABLE `sessions` ( `id` varchar(255) NOT NULL DEFAULT
我必须修复旧 Rails 2.3.8 项目中的错误,但我在加载开发环境时遇到了麻烦。 我已经将项目转换为使用 bundler ,这是我的 Gemfile: source :gemcutter gem
我是 RoR 的新手,我正在按照本教程从头开始制作用户身份验证系统:http://railscasts.com/episodes/250-authentication-from-scratch .我整
我是 Ruby 生态系统的新手,快被淹死了。我想我被带有 C# 的 Visual Studio 的简单智能感知宠坏了。不管怎样,我在 Ubuntu 上使用 Ruby 1.9.3、Rails 3.2.1
通过 M. Hartl 的 Rails 教程第 8 章登录、注销 当我尝试注销我的应用程序时,我收到了问题标题中给出的错误消息。 我对此很陌生,但我认为这意味着在 models/user.rb 中定义
我是一名优秀的程序员,十分优秀!