Add a little magic to common resourceful controllers.
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
LICENSE
README.textile
Rakefile
TODO
merb_resourceful.gemspec

README.textile

merb_resourceful

merb_resourceful is a plugin similar to resource_controller or make_resourceful for rails.

Usage

Generate a new resource (this will change in the future)

merb-gen resource my_resource

Edit app/controllers/my_resources.rb and leave the class declaration only

class MyResources < Merb::Controller resourceful end

This gives you a basic controller with a few defaults (destroy isn’t implemented yet).

Nested resources

class MyResources < Merb::Controller resourceful :belongs_to => :my_parent
  1. The children will be accessed through parent.[children association]
  2. E.g. my_parent.my_resources
  3. this will be configurable in the future
    def my_parent
    @foo ||= session.user.parents.get(params[:foo_id])
    end
    end

Scoped resources

class MyResources < Merb::Controller resourceful :scope => :scope_method
  1. works just like :parent, but doesn’t use @bar for routing
    def scope_method
    @bar ||= session.user.parents.get(params[:bar_id])
    end
    end

Per-action settings

class MyResources < Merb::Controller resourceful do index :layout => ‘my_special_layout’ create :scope => :scope_for_create end def scope_for_create @baz = get_me! end end

Param injection

Merb already supports this with the defer_to method in the router, but I think this is way more explicit.

class MyResources < Merb::Controller resourceful do index :params => lambda {{ :creator => session.user }} # passes :creator as a param to MyResource.new create :params => lambda {{ :creator => session.user }} # passes :creator as a param to the resource’s update method end end

Lots more to come

  • More docs
  • Implement destroy