1

私はroutes.rb次のようなものを持っています:

resources :restaurants, :shallow => true do
  resources :orders do
    resources :foods
  end
  resources :categories do
    resources :foods
  end
end

私のability.rb作品では、このようなもの、

if user.role? :owner
  can :manage, Category, :restaurant => {:user_id => user.id}
  ...

しかし、浅いネスティングでは、より深いネスティングが問題になるようです。

  can :manage, Food, :category => {:restaurant => {:user_id => user.id}}
end

最後の例と同じくらい深いネストを処理するために CanCan を取得する方法についてのアイデアはありますか?

4

1 に答える 1

1

ありえないと思います。ブロックを使用して自分で行う必要があります:
https://github.com/ryanb/cancan/wiki/Defining-Abilities-with-Blocks

can :manage, Food do |food|
    food.categories.joins(:restaurant).where("restaurants.user_id = ?", user.id).any?
end

あなたは正確に何をしたいですか?ユーザーがカテゴリを介して所有するレストランに属している場合、ユーザーは食品のみを管理できますか?

于 2012-01-02T19:31:28.940 に答える