new_resource is hobbled, but I can't smoothly override it

4 views
Skip to first unread message

Chris Hapgood

unread,
Dec 18, 2009, 9:59:36 AM12/18/09
to resources_controller
First, the default new_resource method needs to support the block
initialization scheme. For example:

new_resource do |widget|
widget.foo = "bar"
end

The fix is so trivial, I won't bother writing it out (particularly
since I'm not an rspec'er)

------------------

A suggestion: custom actions module should also support custom find/
new_resource methods. Unfortunately, if you put a custom new_resource
method in an action module, it still gets overridden by the default.

Chris Hapgood

unread,
Dec 18, 2009, 10:59:56 AM12/18/09
to resources_controller
Scratch that last comment: I had flagged my custom new_resource method
as private.

Chris Hapgood

unread,
Dec 18, 2009, 2:17:37 PM12/18/09
to resources_controller
Actually, my original comment is still valid. It does not seem
possible to OVERRIDE the new_resource method in an included action
module. This, for example:

class FeedsController < ApplicationController
resources_controller_for :feeds, :actions
=> ::Hapgood::OwnedDataActions
end

does not work. Here is my workaround:

class FeedsController < ApplicationController
include ::Hapgood::OwnedDataActions
resources_controller_for :feeds, :actions => false
end

-Chris

Chris Hapgood

unread,
Dec 18, 2009, 2:55:21 PM12/18/09
to resources_controller
Here is what is going on: http://osdir.com/ml/ruby-talk/2009-09/msg01003.html

A solution would be to move the RC version of new_resource to a module
and include that module BEFORE including the actions module.

This is definitely nit-picking though. The only reason I need it now
is to wire in support for block initialization.

Ian White

unread,
Dec 20, 2009, 4:03:10 AM12/20/09
to resources_...@googlegroups.com
Hi Chris,

> A solution would be to move the RC version of new_resource to a module
> and include that module BEFORE including the actions module.

This is a good idea, and something I've been meaning to do for a while
anyway - it will also allow super calls when you;re overriding
find_resource ect.

Cheers,
Ian

> --
>
> You received this message because you are subscribed to the Google
> Groups "resources_controller" group.
> To post to this group, send email to resources_...@googlegroups.com
> .
> To unsubscribe from this group, send email to resources_contro...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/resources_controller?hl=en
> .
>
>

Ian White

unread,
Dec 20, 2009, 5:01:06 AM12/20/09
to resources_...@googlegroups.com
Hi Chris,

Both of these issues are now fixed - please try them out and let me
know how it goes. Here's the spec that tests these features: http://github.com/ianwhite/resources_controller/blob/master/spec/lib/resource_methods_spec.rb

Cheers,
Ian

Chris Hapgood

unread,
Dec 21, 2009, 12:21:05 PM12/21/09
to resources_controller
I can confirm both: block initialization now works, and I can override
new_resource in an actions module.

As usual, Ian is on top of his game!

PEOPLE: spread the word, this RC thing is truly useful.


On Dec 20, 5:01 am, Ian White <ian.w.wh...@gmail.com> wrote:
> Hi Chris,
>
> Both of these issues are now fixed - please try them out and let me  

> know how it goes.  Here's the spec that tests these features:http://github.com/ianwhite/resources_controller/blob/master/spec/lib/...

Reply all
Reply to author
Forward
0 new messages