0
我有以下型號:CanCan,建立一個嵌套資源?
Group (id)
Poll (id, group_id)
PollVote (id, poll_id)
我不想做深嵌套,這意味着我不希望/組/:ID /調查/:ID/poll_vote /:ID
我想設定,讓我的路線:
/group/:id
/poll/:id
/poll/:id/poll_vote/:poll_vote_id
我有民意調查工作,但我無法弄清楚如何獲得PollVote工作......到目前爲止,我有:
class PollVotesController < ApplicationController
# Authorization w Devise & CanCan
before_filter :authenticate_user! # Devise, signed in users only
load_and_authorize_resource :poll # CanCan
load_and_authorize_resource :poll_vote, :through => :poll
# We need to pass along the wall
def current_ability
@current_ability ||= Ability.new(current_user, @poll.group_id)
end
然後在ability.rb
can [:manage], Poll do |poll|
This returns TRUE is the user is a group member of the poll
end
有什麼值得我PollVotes使用,有PollVotes慘慘使用輪詢檢查?
感謝
傑里米,感謝這個...我很困惑什麼是ability.rb我還需要一個能:管理,PollVote? – AnApprentice
另外,我如何將它鎖定爲僅與用戶相關的投票?非常感謝,CanCan – AnApprentice
@AnApprentice:我在答案中添加了更多示例。 –