Forum: Ruby on Rails Using view helpers in migrations?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Josh on Rails (Guest)
on 2007-01-16 05:45
(Received via mailing list)
I'm writing a bloggish/CMSish thing. I had been using simple_format,
but my users requested a rich editor, so I added TinyMCE.

Anyway, I was trying to migrate the existing content (since TinyMCE
assumes it's reading HTML-formatted text), and realized that I
couldn't call simple_format (or other helper methods) from Migrations.

Can someone enlighten me here?
Andrew S. (Guest)
on 2007-01-16 06:37
Josh on Rails wrote:
> I'm writing a bloggish/CMSish thing. I had been using simple_format,
> but my users requested a rich editor, so I added TinyMCE.
>
> Anyway, I was trying to migrate the existing content (since TinyMCE
> assumes it's reading HTML-formatted text), and realized that I
> couldn't call simple_format (or other helper methods) from Migrations.
>
> Can someone enlighten me here?

I am not sure about accessing the helpers from migrations, but you could
use Blue/red cloth instead.
Snow M. (Guest)
on 2007-01-16 08:16
If you really want access to the helpers from somewhere outside a view
you can just include them manually. Just be aware that you may have to
include several helpers if they depend on eachother, and if a helper
depends on something in ActionView::Base then it won't work outside the
view. Here's an example of one that does work:


require File.dirname(__FILE__) + '/config/environment'

class Test
  include ActionView::Helpers::TextHelper
  def print_message
    puts truncate("The quick brown fox jumps over the lazy dog.", 20)
  end
end

Test.new.print_message

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

prints:

The quick brown f...
This topic is locked and can not be replied to.