Rails console - use image_tag method
Asked Answered
E

2

12

How can I execute a image_tag method in a Rails console

  1. Run the console $ rails c

  2. Load helpers

    include ActionView::Helpers

  3. Execute the command

    image_tag('test.png')

I got a strange error. alt text

Please help!

Ectophyte answered 4/11, 2010 at 20:16 Comment(0)
E
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.

Ectophyte answered 4/11, 2010 at 21:16 Comment(0)
D
23

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')
Diatribe answered 4/11, 2010 at 20:52 Comment(0)
E
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.

Ectophyte answered 4/11, 2010 at 21:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.