【发布时间】:2014-10-17 04:47:06
【问题描述】:
我是 Ruby on Rails 的新手,在使用 devise 配置 typus 时遇到问题。
我有一个 Rails REST 应用程序(使用 rails_api 构建),它使用设计来进行身份验证。目前我正在开发一个新的 Rails 应用程序,它应该是使用 typus 的 REST 应用程序的管理页面。最终,我的目标是让这个管理应用程序访问与之前构建的 REST 应用程序相同的数据库,同时使用 REST 应用程序的现有设计模型。但是,即使用户存在于数据库中,我也会不断收到 401 Unathorized 消息。
确切地说,我在 REST 应用程序中有一个设计模型 Account,我想在我的管理应用程序中使用这个特定的设计模型作为设计模型。我将模型 Account(以及其他模型)从 REST 应用程序复制到新的管理应用程序,然后,我按照 this 将 typus 配置为使用 devise 进行身份验证,但没有生成新的 devise 模型:
rails generate devise:install
rails generate typus
# config/initializers/typus.rb
Typus.setup do |config|
config.authentication = :devise
config.user_class_name = "Account"
end
# edit the devise model: Account
require 'typus/orm/active_record/instance_methods'
class Account < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, :confirmable
include Typus::Orm::ActiveRecord::InstanceMethods
def locale
::I18n.locale
end
def role
Typus.master_role
end
end
# routes.rb
Rails.application.routes.draw do
devise_for :accounts
end
# initializers/devise.rb
# make secret_key the same with REST app's secret_key
config.secret_key = 'identic-secret-key-with-rest-app'
当我运行服务器并尝试使用数据库中的现有用户(来自 REST 应用程序的用户)登录时,它总是在服务器控制台中显示 401 Unauthorized。我的配置中有什么遗漏的吗?甚至我的方法是可行的?
如果我为管理应用生成一个新的设计模型,效果会很好。
【问题讨论】:
-
感谢@NitinVerma 解决了我的问题
标签: ruby-on-rails ruby ruby-on-rails-4 devise typus