ブログ アプリに宣言型承認を実装しました。これで、管理者、認証済みユーザー、およびゲスト ユーザー用にそれぞれ 3 つのレイアウトができました。そのため、特定の時間にアプリを使用しているユーザーのタイプを確認する必要があります。ユーザーモデル、ロールモデル、割り当てモデルがあります。
ユーザー.rb
class User < ActiveRecord::Base
attr_accessible :login, :email, :password, :password_confirmation, :role_ids
has_many :articles
has_many :comments
has_many :assignments
has_many :roles, :through => :assignments
def role_symbols
roles.map do |role|
role.name.underscore.to_sym
end
end
acts_as_authentic do |c|
c.login_field = :login
end
def deliver_password_reset_instructions!
reset_perishable_token!
Notifier.deliver_password_reset_instructions(self)
end
end
割り当て.rb
class Assignment < ActiveRecord::Base
belongs_to :user
belongs_to :role
end
Role.rb
class Role < ActiveRecord::Base
attr_accessible :name
has_many :assignments
has_many :users, :through => :assignments
end
解決策はありますか?