Merb controllers cannot be modules because modules are not
instantiatable. The way merb's thread safety works is by
instantiating a new controller object for each new request/thread.
-Ezra
On Sep 20, 2007, at 1:13 PM, ry dahl wrote:
> On 9/20/07, John Weir <[EMAIL PROTECTED]> wrote:
>> how would filters and common methods work?
>
> one way this could be done is by attaching a filters as class methods
> to the actions. for example
>
> module Controllers::Products
> before Index, Show do |request|
> raise Unauthorized unless request.session[:user].admin?
> end
> ...
> end
>
> would take the block argument, add do
> Index.class_eval { @@before_filter = block }
> for both Index and Show. At the time of request, the dispatcher could
> call that block before instantiating the action.
>
> this is just an example for entertaining the idea - not a proposal - i
> haven't thought all the way through it
>
>
>>> 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?
>>>>
> _______________________________________________
> Merb-devel mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/merb-devel
-- Ezra Zygmuntowicz
-- Founder & Ruby Hacker
-- [EMAIL PROTECTED]
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)
_______________________________________________
Merb-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/merb-devel