No commit activity in last 3 years
No release in over 3 years
merb_resourceful lends a little magic to common resource actions.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 1.0
 Project Readme

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