我正在解决一个我无法解决的问题。
我有以下内容:
组表:
create_table "groups", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
团契表:
create_table "groupships", :force => true do |t|
t.integer "group_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "owner"
t.text "permission"
end
组.rb:
class Group < ActiveRecord::Base
belongs_to :user
has_many :groupships
has_many :groups, through: :groupships
end
groupship.rb:
class Groupship < ActiveRecord::Base
belongs_to :user
belongs_to :group
end
我想通过 groupship 查看用户是否是组的所有者以及用户具有哪些权限。这可能吗,还是我必须制作一个 group_perssions 表?
我在一个视图中尝试了这个:
<% @groups.each do |group| %>
<div class="well well-small">
<h3><%= group.name %></h3>
Owner: <%= group.groupships.owner %> //True or false readout for development.
</div>
<% end %>