For example,
module Controllers::Products
class Index < GetAction
def initialize(params)
@products = Product.paginate(params[:page] || 1)
end
def response_json
@products.to_json
end
def response_html
render 'products/index.erb'
end
end
class Show < GetAction
extra_route ':id'
def initialize(params)
@products = Product.find(params[:id])
end
def response_html
render 'products/show.erb'
end
end
end
<%= link_to 'Products', Controllers::Products::Index.url %>
On 9/20/07, ry dahl <[EMAIL PROTECTED]> wrote:
> Sometimes it seems like actions deserve to be their own objects: we
> map routes to them, we'd like to know what parameters they expect, we
> want to say which http methods they accept, we assign them
> before/after filters, and we even hold collections of them
> (Controller.callable_actions). This responds_to issue is another
> example of how we'd like to treat actions as objects. We would like
> for the controller to look at the request, determine which format to
> send, and then simply call my_action.render_json or
> my_action.render_html. Simultaneously, our controllers are not very
> class like. They are basically instantiate them only to call the
> action. Changing the Controller class into a module would not be so
> hard in the current Merb - they are (more or less) just containers for
> actions.
>
> Has anyone else been having these thoughts?
>
> ry
_______________________________________________
Merb-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/merb-devel