У меня есть представление, показывающее пользователя и роли. Я могу заставить его показать всех пользователей и одну роль с user.roles.first.name. Я не могу заставить его зациклиться и получить все роли для выбранного пользователя. Любая помощь будет замечательной.Devise and Rolify - Показать всех пользователей - роли - Несколько ролей
<h1>Admin#users</h1>
<p>Find me in app/views/admin/users.html.erb</p>
<ul>
<table class="table-bordered col-md-6 ">
<% @users.each do |user| %>
<tr>
<td><%= link_to user.email, edit_user_path(user) %></td>
#guess a loop here .. unable to find how to show all of a users roles.
<td><%= user.roles.first.name %></td>
# end loop
<td><%= user.id %></td>
</tr>
<% end %>
</table>
</ul>
Администратор контроллера: класс
class AdminController < ApplicationController
before_action :authenticate_user!
authorize_resource :class => AdminController
def dashboard
@user = current_user
end
def users
@users = User.all
end
end
Пользователь: класс
class User < ActiveRecord::Base
rolify
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
end
Роль:
class Role < ActiveRecord::Base
has_and_belongs_to_many :users, :join_table => :users_roles
belongs_to :resource, :polymorphic => true
validates :resource_type,
:inclusion => { :in => Rolify.resource_types },
:allow_nil => true
scopify
end