问题
How can I execute a image_tag method in a Rails console
Run the console $ rails c
Load helpers
include ActionView::Helpers
Execute the command
image_tag('test.png')
I got a strange error.
Please help!
回答1:
Not sure why you're getting that error. It is strange.
But the Rails Console exposes the helper methods through the helper variable. So this should work:
helper.image_tag('test.png')
回答2:
OK... I found the solution. The error is showing only in Rails 3 but I fixed it by setting the
config.action_controller.asset_host = "http://..."
config.action_mailer.asset_host = "http://..."
in my environemnt file (e.g. development.rb). Unbelievable!
This functionality is now part of a plugin https://github.com/xpepermint/js_erb.
来源:https://stackoverflow.com/questions/4100929/rails-console-use-image-tag-method