Read more

Consul 0.10.0 allows multiple power mappings for nested resources

Henning Koch
August 28, 2013Software engineer at makandra GmbH

Consul Show archive.org snapshot 0.10.0 now allows multiple power mappings for nested resources.


Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

When using nested resources Show archive.org snapshot you probably want two power
checks and method mappings: One for the parent resource, another for the child resource.

Say you have the following routes:

resources :clients do
  resources :notes
end

And the following power definitions:

class Power
  ...

  power :clients do
    Client.active if signed_in?
  end

  power :client_notes do |client|
    client.notes.where(:state => 'published')
  end

end

You can now check and map both powers in the nested NotesController:

class NotesController < ApplicationController

  power :clients, :as => :client_scope
  power :client_notes, :context => :load_client, :as => :note_scope

  def show
    load_note
  end

  private

  def load_client
    @client ||= client_scope.find(params[:client_id])
  end

  def load_note
    @note ||= note_scope.find(params[:id])
  end

end

Note how we provide the Client parameter for the :client_notes power by using the :context => :load_client
option in the power directive.

Posted by Henning Koch to makandra dev (2013-08-28 12:32)