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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)