rubyonrailsin

A Ruby and Rails talk

Thursday, April 1, 2010


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

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

Hi Arek,

Just published my article:
http://blog.endpoint.com/2010/03/spree-software-development.html

I've typically found it cleaner to move everything out of the
*extension_name*_extension.rb file, for better organization and for
better repo management with the module includes shown in the article.
The article doesn't include any surprising ruby techniques, but after
working on several projects lately with multiple developers, it has
become pretty important to have well organized code.

~Steph


Arek Flinik wrote:
> 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
> <mailto: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
> <mailto: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
> <mailto:spree-user@googlegroups.com>.
> To unsubscribe from this group, send email to
> spree-user+unsubscribe@googlegroups.com
> <mailto:spree-user%2Bunsubscribe@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.

--
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