How to override url_for_event in Apotomo to always include a parameter?

33 views
Skip to first unread message

Ramon Tayag

unread,
Jun 21, 2011, 11:22:17 AM6/21/11
to cells-an...@googlegroups.com
Hey all,

I want to be able to add some default parameters to the url_for_event helper. How do you do this?


Ramon Tayag

Nick Sutterer

unread,
Jun 21, 2011, 4:30:20 PM6/21/11
to cells-an...@googlegroups.com
Hey Ramon,

try overriding Widget#default_url_options in your widget, this would
be a first step. That should work!

Nick

Ramon Tayag

unread,
Jun 21, 2011, 9:54:56 PM6/21/11
to cells-an...@googlegroups.com
Hello Nick,

Is there a way to do this for all widgets in the app automatically?

Ramon Tayag

Paul Hagstrom

unread,
Jun 21, 2011, 10:08:41 PM6/21/11
to cells-an...@googlegroups.com
You should be able to create a base widget and then make the rest of your widgets inherit from that one. It requires a one-time change to all of your widgets, but I wouldn't imagine that's a huge number of changes to make.

class YourBaseWidget < Apotomo::Widget
def default_url_options
...
end
end

class YourOtherWidgets < YourBaseWidget
...
end

That's the approach I'd take, at least. I expect there's a way to reopen Apotomo's own class in part of the Rails initialization process, and replace default_url_options across the board that way. The only thing then is that when you are looking at your widgets themselves, they will appear to depend only on Apotomo; it would be easy to forget that it's patched.

-Paul

Ramon Tayag

unread,
Jun 21, 2011, 10:23:15 PM6/21/11
to cells-an...@googlegroups.com
Yes, I like this approach. I'll go try it.

Thanks,
Ramon Tayag

Ramon Tayag

unread,
Jun 21, 2011, 11:30:16 PM6/21/11
to cells-an...@googlegroups.com
This worked perfectly, thanks!

I think this approach should be promoted and made the standard way of making widgets, whether or not people apply methods across the board. It's just like how all controllers inherit from ApplicationController. All widgets should inherit from ApplicationWidget :)

Ramon Tayag



On Wed, Jun 22, 2011 at 10:08 AM, Paul Hagstrom <hags...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages