1

チュートリアルhttps://github.com/EppO/rolify/wiki/Tutorialに従っただけで、とても素晴らしく、うまく機能しています。しかし、私の質問は、Rails コンソールを使用せずにフォームから Role を追加できないかということです。

<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) に接続します。

これが私のrole.rbです

class Role < ActiveRecord::Base

has_and_belongs_to_many :users, :join_table => :users_roles

所属先 :resource, :polymorphic => true

ユーザー.rb

クラス User < ActiveRecord::Base

所属先:アカウント, :inverse_of => :ユーザー

:account, :presence => true を検証します

ろくでなし

attr_accessible :role_ids

# デフォルトのデバイス モジュールを含めます。# :確認可能、:ロック可能、:タイムアウト可能、および:オムニ認証可能

:database_authenticatable、:registerable、:recoverable、:rememberable、:trackable、:validatable

# モデルのアクセス可能な (または保護された) 属性をセットアップする

attr_accessible :email、:password、:password_confirmation、:remember_me、:role_ids

# attr_accessible :title, :body

has_many :auditinits

終わり

どんな助けでも大歓迎です!!

4

1 に答える 1