rubyonrailsin

A Ruby and Rails talk

Wednesday, March 31, 2010


Re: [spree-user] Re: Overriding existing controller in extension

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

Hi,


thanks for quick response. I've actually managed to do exactly the same thing (calling class_eval from activate method in my extension class -- is it the right place?). I just thought it could be done somehow prettier, but it seems it's not possible to extend controllers like you can do it with routes or i18n files. 

On a side note, it's still possible to use resource_controller's methods to make code cleaner and easier to read, also it doesn't abandon existing hooks (like create.before which is by default in OrdersController). Corresponding code would look as follows:

OrdersController.class_eval do
         create do
            #something
         end
end

Thank you kindly anyway,

Arek

On Wed, Mar 31, 2010 at 8:33 PM, McKenzie <ryan@souliss.com> wrote:
Hi Arek,

You can override a method in your extension by using the following:

OrdersController.class_eval do
         def create
            #insert new action here
         end
end

Hope that helps

Ryan

On Mar 31, 7:02 pm, Arek Flinik <afli...@gmail.com> wrote:
> Hi,
>
> I'd like to create extension which would override just one method in
> existing controller (in this case, create action in OrdersController).
> After hours of trying i've ran out of ideas on how to do it withous
> copy-pasting existing controller file. Does anyone have an idea on how
> to do it in nice and clean way?
>
> Thanks,
> Arek Flinik

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


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

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive