While we are on the subject of resources, here is another idea I wanted to
share.

I added a method called #owner to Application. It dives into params and
finds the owner of the current resource. That is, if the route is
parents/1/children, the owner would be the Parent instance with ID 1. We
have some routes where the same resource class can have different parents,
so having the owner abstraction is very helpful in having DRY controllers. I
wondered if other folks would find this useful. If so, we could discuss a
generalized way to add this to the core. Perhaps this would be part of the
new Resource class under development.

On a related note, it would be great to have a #resource method in
Controller that would grab :id from params and instantiate the class. No
more foo = Foo.get(id) all over the controller code!

..tony..

On Wed, Dec 17, 2008 at 12:26 PM, Tony Mann <[email protected]> wrote:

> Jacques,
>
> Any automated solution would have to be smart about action-args, too. For
> example, imagine the index action requires a parent_id:
>
> class Children
>   def index(parent_id)
>   end
> end
>
> Then
>
> resources :children
>
> would not generate an index action, but
>
> resources :parent do
>   resources :children
> end
>
> would generate the index action.
>
> ..tony..
>
>
> On Wed, Dec 17, 2008 at 12:19 PM, Jacques Crocker <[email protected]>wrote:
>
>>
>> Seems like it would be even simpler if before defining each route (for
>> a resource), it did a respond_to? on the controller class to check for
>> the associated method. If the method doesn't exist, then just don't
>> define the route.
>>
>> 3-4 lines of code to implement and no new syntax and configuration
>> needed.
>>
>> On Dec 17, 12:13 pm, "Tony Mann" <[email protected]> wrote:
>> > I do indeed admire the simplicity of the resources syntax, especially
>> with
>> > the block parameters gone. However, a small addition to the syntax in
>> order
>> > to select which actions to support does not seem overly complex to me.
>> For
>> > example:
>> >
>> > resources :foo, :actions => [:index, :update]
>> >
>> > ..tony..
>> >
>> > On Wed, Dec 17, 2008 at 11:43 AM, Michael Klishin <
>> >
>> > [email protected]> wrote:
>> >
>> > > On 17.12.2008, at 21:05, Tony Mann wrote:
>> >
>> > > > This is why I am looking forward to the Resource enhancements that
>> > > > Yehuda keeps mentioning. It would be great to have a more concise
>> > > > way of specifying the CRUD routes.
>> >
>> > > Keep in mind Merb router is already quite powerful and quite complex.
>> > > Making it even more complex may not be worth new features, that's one
>> > > of the reasons why some of them are still not implemented. So, ask
>> > > yourself: are shallow routes worth losing Merb core simplicity? They
>> > > may be worth it, I won't judge.
>> >
>> > > MK
>> >>
>>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to