私は解決できない問題に取り組んでいます。
私は次のものを持っています:
グループ表:
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
group.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
グループシップを通じて、ユーザーがグループの所有者であるかどうか、およびユーザーがどのような権限を持っているかを確認したいと考えています。それは可能ですか、それとも 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 %>