Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3: Ruby url_encode method not found; undefined method `u' for #<SiteController:0x007fe447774da8>

I have a simple line of code: @keyword = u @keyword and rails is throwing me an exception that it's not a method:

undefined method 'u' for #<SiteController:0x007fe447774da8>

I am upgrading this app from Rails 2 to Rails 3. Was the url_encode method replaced by something else? It's hard to find documentation for it. I'm using the method in my controller.

like image 652
bigpotato Avatar asked Feb 08 '26 00:02

bigpotato


1 Answers

Try URI::encode():

require 'open-uri'
@keyword = URI::encode(@keyword)

I think URI.escape() should also work <- deprecated in Ruby 1.9.2 apparently.
You can use CGI.escape instead of the above, not sure of the difference, if any.

And you can still use url_encode if you do the following:

require "erb"
include ERB::Util

@keyword = u(@keyword)
like image 54
mind.blank Avatar answered Feb 17 '26 05:02

mind.blank



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!