Using view helpers in migrations?

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?

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.

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…