ryanb / cancan

Authorization Gem for Ruby on Rails.
MIT License
6.28k stars 785 forks source link

3rd child association and accessible_by(current_ability) #846

Open thesubr00t opened 11 years ago

thesubr00t commented 11 years ago

I have a 3 level association as follow:

User has_one Hotel
Hotel has_many Rooms
Room has_many Prices

I have defined the ability as follow:

def initialize(user)
  unless user.nil?
    can :manage, Hotel, user_id: user.id
    can [:update, :delete, :read], Room, hotel: { user_id: user.id }
    can [:update, :delete, :read], Price, room: { hotel: { user_id: user.id } }
  end
end

When I call accessible_by(current_ability) on the prices_controller index action:

@search = Price.accessible_by(current_ability).search(params[:q])
@prices = @search.result.page params[:page]
# Also using Ransack & Kaminari

It gives the error Mysql2::Error: Unknown column 'rooms.hotels' in 'where clause': SELECTprices.* FROMpricesINNER JOINroomsONrooms.id=prices.room_idINNER JOINhotelsONhotels.id=rooms.hotel_idWHERErooms.hotels= '---\n:user_id: 2\n' LIMIT 5 OFFSET 0

Here is the complete development log.

the8472 commented 11 years ago

You're probably running into #646

xhoy commented 10 years ago

Dear submitter, Since cancan/raynB hasn't been active for more than 6 months and no body else then ryam himself has commit permissions the cancan project is on a stand still. Since cancan has several issues including missing support for rails 4 cancan is moving forward to cancancan. More details on: #994

If your feel that your pull request or bug is still applicable (and hasn't been merged in to cancan) it would be really appreciated if you would resubmit it to cancancan (https://github.com/cancancommunity/cancancan)

We hope to see you on the other side!