授权深度嵌套的资源

时间:2014-10-08 07:40:30

标签: ruby-on-rails ruby-on-rails-4

我有嵌套的资源,看起来像这样;

 resources :users do     
    resources :businesses do
      resources :business_accounts, path: "business_account", only: [:show] do 
        resources :business_withdraws
        resources :business_deposits
      end
    end
  end

我无法访问链接/users/1/businesses/2/business_account/1/business_deposits/new和其他商业存款路径。

我试过这个,这给了我们一个错误,

can [:read, :create], BusinessDeposit, business: {business_account:{user_id: user.id}}         
    can [:read, :create], BusinessWithdraw, business: {business_account:{user_id: user.id}}

然后这个,

       can [:read, :create], BusinessDeposit do |deposit|
            deposit.business_account_id == user.business.business_account.id
        end
        can [:read, :create], BusinessWithdraw do |withdraw| 
            withdraw.business_account_id ==  user.business.business_account.id
        end

只是让它无法访问

class User < ActiveRecord::Base
   has_one :business
end
class Business < ActiveRecord::Base
    belongs_to :user
    has_one :business_account
end
class business_account < ActiveRecord::Base
    belongs_to :business
    has_many :business_withdraws
    has_many :business_deposits
end

1 个答案:

答案 0 :(得分:0)

你可以尝试:

can [:read, :create], BusinessDeposit, business_account: {business: {user: user}}   
相关问题