The time when I find it most necessary is to write flash memory or custom error checks. In some cases, it's nice to use things like link_to helpers in a flash message. I use the following solution to get ActionView helpers in the controller. Keep in mind that, as mentioned above, this breaks the MVC separation, so if anyone else has a better idea, let me know!
Below ApplicationController add this:
class Something include Singleton include ActionView::Helpers::UrlHelper end
and inside ApplicationController add
def foo Something.instance end
and finally, in the controller, where you want to access the auxiliary code:
messages << "<li class='error'>Your have an Error!<%= foo.link_to('Fix This', some_path) %></li>"
Hope this helps in some way!
Scott Miller Jan 17 '09 at 21:11 2009-01-17 21:11
source share