Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using helper methods like html_escape in rails console

I am trying to see what is going wrong with my encoding of variables in my view. So I fire up rails console and try to do

$ rails console
Loading development environment (Rails 3.2.11)
irb(main):001:0> html_escape({:a=>1, :b=>"my str"})
NoMethodError: undefined method `html_escape' for main:Object

How do I use h or html_escape in rails console?

like image 862
highBandWidth Avatar asked Mar 01 '13 17:03

highBandWidth


2 Answers

Easy to solve. html_escape is defined in ERB::Util so simply write:

include ERB::Util

in your console prior to the first use of html_escape

like image 172
boulder Avatar answered Oct 29 '22 19:10

boulder


you call it through helper. some methods are private so you may need to use send to call them

helper.send(:html_escape, '123')
helper.pluralize 3, 'user'
like image 39
jvnill Avatar answered Oct 29 '22 17:10

jvnill