【发布时间】:2014-05-28 03:55:55
【问题描述】:
我刚刚按照教程 "https://github.com/EppO/rolify/wiki/Tutorial" 它非常好并且工作正常。但是我的问题是我们不能在不使用 Rails 控制台的情况下通过表单添加角色。
<div class="field"><%= user_form.label :email %><br />
<%= user_form.email_field :email %></div>
<div class="field"><%= user_form.label :password %><br />
<%= user_form.password_field :password %></div>
<div class="field"><%= user_form.label :password_confirmation %><br />
<%= user_form.password_field :password_confirmation %></div>
<div class="field">
<%= f.label :roles %>
<div class="controls">
<% Role.all.each do |role| %>
<%= check_box_tag "user[role_ids][]", role.id, @user.role_ids.include?(role.id) %>
<%= role.name %><br />
<% end %>
</div>
</div>
<% end %>
角色列连接到角色表(Rolify Roles)
这是我的角色.rb
类角色<:base>
has_and_belongs_to_many :users, :join_table => :users_roles
belongs_to :resource, :polymorphic => true
User.rb
类用户<:base>
belongs_to :account, :inverse_of => :users
验证 :account, :presence => true
罗列
attr_accessible :role_ids
# 包括默认设计模块。其他可用的有: # :confirmable, :lockable, :timeoutable 和 :omniauthable
设计 :database_authenticable, :registerable, :recoverable, :rememberable, :trackable, :validatable
# 为您的模型设置可访问(或受保护)的属性
attr_accessible :email, :password, :password_confirmation, :remember_me, :role_ids
# attr_accessible :title, :body
has_many :auditinits
结束
感谢任何帮助!
【问题讨论】:
标签: ruby ruby-on-rails-3 devise cancan rolify