我对红宝石很陌生,几个月来我一直在为此苦苦挣扎。我进行了广泛的搜索并尝试了答案所说的内容,但仍然没有运气。(我尝试了使用 Ruby On Rails 的多用户模型,并设计了单独的注册路径,但有一个通用的登录路径,但没有用)
我目前有一个 user.rb 模型,它连接到设计并且工作正常。
1- 在注册页面上,我想有 3 个按钮,它们会导致单独的注册表单(业务、经理和现有用户各一个)。我是否在 routes.rb 中进行了设置?2-表单将具有不同的属性,这些属性将填充各自的数据库。3- 填写完表格后,他们将被引导到各自的路线。用户到当前默认路由,而业务到业务仪表板,经理到经理仪表板。这又是在 routes.rb 中还是在设计中?
我将不胜感激任何指导!
我已经阅读了设计、cancan 和 rolify 的文档,但我似乎无法将它们整合在一起为我工作。
我对红宝石很陌生,几个月来我一直在为此苦苦挣扎。我进行了广泛的搜索并尝试了答案所说的内容,但仍然没有运气。(我尝试了使用 Ruby On Rails 的多用户模型,并设计了单独的注册路径,但有一个通用的登录路径,但没有用)
我目前有一个 user.rb 模型,它连接到设计并且工作正常。
1- 在注册页面上,我想有 3 个按钮,它们会导致单独的注册表单(业务、经理和现有用户各一个)。我是否在 routes.rb 中进行了设置?2-表单将具有不同的属性,这些属性将填充各自的数据库。3- 填写完表格后,他们将被引导到各自的路线。用户到当前默认路由,而业务到业务仪表板,经理到经理仪表板。这又是在 routes.rb 中还是在设计中?
我将不胜感激任何指导!
我已经阅读了设计、cancan 和 rolify 的文档,但我似乎无法将它们整合在一起为我工作。
#user.rb
class User < ActiveRecord::Base
has_many :contibutions
rolify
# Include default devise modules. Others available are:
# :lockable, :timeoutable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
validates_format_of :email, :without => TEMP_EMAIL_REGEX, on: :update
def admin?
has_role?(:admin)
end
def self.find_for_oauth(auth, signed_in_resource = nil)
# Get the identity and user if they exist
identity = Identity.find_for_oauth(auth)
user = identity.user
if user.nil?
# Get the existing user from email if the OAuth provider gives us an email
user = User.where(:email => auth.info.email).first if auth.info.email
# Create the user if it is a new registration
if user.nil?
user = User.new(
name: auth.extra.raw_info.name,
#username: auth.info.nickname || auth.uid,
email: auth.info.email.blank? ? TEMP_EMAIL : auth.info.email,
password: Devise.friendly_token[0,20]
)
user.skip_confirmation!
user.save!
end
# Associate the identity with the user if not already
if identity.user != user
identity.user = user
identity.save!
end
end
user
end
end