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_resourceEdit app/controllers/my_resources.rb and leave the class declaration only
class MyResources < Merb::Controller resourceful endThis gives you a basic controller with a few defaults (destroy isn’t implemented yet).
Nested resources
- The children will be accessed through parent.[children association]
- E.g. my_parent.my_resources
- this will be configurable in the future
def my_parent
@foo ||= session.user.parents.get(params[:foo_id])
end
end
Scoped resources
- 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
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 endLots more to come
- More docs
- Implement destroy