# Error: private method \`gsub' called for :city:Symbol

**URL:** <https://www.ruby-forum.com/t/error-private-method-gsub-called-for-symbol/71527>\
**Category:** Ruby\
**Created:** [October 9, 2006, 6:32pm UTC](https://www.ruby-forum.com/t/error-private-method-gsub-called-for-symbol/71527 "2006-10-09T18:32:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 9, 2006, 6:32pm UTC](https://www.ruby-forum.com/t/error-private-method-gsub-called-for-symbol/71527/1 "2006-10-09T18:32:06Z")

</div>

I googled around on this one but found nothing. Anyone know what these  
error means ?  
I’m trying to use it in a form field :

\<%= text\_field(:search,:city.gsub(/\s/, “’’”)) %\>

But also found the same error when using it on an instance variable.

TIA  
Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 9, 2006, 6:36pm UTC](https://www.ruby-forum.com/t/error-private-method-gsub-called-for-symbol/71527/2 "2006-10-09T18:36:10Z")

</div>

On 10/9/06, Dark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Stuart  
> Also I found another place to add it and it inserted some backslahes  
> so the orignal text is ‘atlanta boston’  
> I’m trying to insert 2 ‘’ between atlanta and boston which works fine  
> standalone but in my app (inserted into a query) it comes out as such  
> ‘boston''atlanta’  
> But if I leave the regex out it’s as shown above

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 9, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/error-private-method-gsub-called-for-symbol/71527/3 "2006-10-09T18:52:12Z")

</div>

On Tue, Oct 10, 2006, Dark A. wrote:

> I googled around on this one but found nothing. Anyone know what these  
> error means ?

It means exactly what the exception says. You can’t call gsub on a  
symbol.

> I’m trying to use it in a form field :
> 
> \<%= text\_field(:search,:city.gsub(/\s/, “’’”)) %\>

That doesn’t do what you think it does.

text\_field takes two arguments, the first is the object it represents,  
and the second is the attribute of that object that the value will be  
saved into/pulled out from.

It seems that you want to massage that value before it gets inserted  
into the form field, right? Or is it after it gets saved?

In the former case, you can (probably!) specify a value manually, like  
so:

\<%= text\_field :search, :city, :value =\> @search[:city].gsub(/\s/, “’’”)  
%\>

In the latter case, do this in your model.

Ben

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 9, 2006, 6:56pm UTC](https://www.ruby-forum.com/t/error-private-method-gsub-called-for-symbol/71527/4 "2006-10-09T18:56:12Z")

</div>

On 10/9/06, Dark A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > TIA  
> > Stuart
> 
> Also I found another place to add it and it inserted some backslahes  
> so the orignal text is ‘atlanta boston’  
> I’m trying to insert 2 ‘’ between atlanta and boston which works fine  
> standalone but in my app (inserted into a query) it comes out as such  
> ‘boston''atlanta’  
> But if I leave the regex out it’s as shown above

Well the regex isn’t doing what you think it’s doing. Rails  
automagically  
converts :city, to the value of a field in your model named City. When  
you  
say :city.gsub Ruby reads this as “do a gsub on the symbol :city”, it  
doesn’t know that later on Rails will make that a string with another  
value. IMO the easiest way around this would be to not use the helper  
and  
do something like:

\<input type=“text” name=“city” value=“\<%=@search.city.gsub(/\s/,”‘’“)  
%\>”/\>

But that’s just off the top of my head, and I don’t do a lot of Rails  
work,  
so take it with a slight grain of salt.

Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [October 9, 2006, 7:58pm UTC](https://www.ruby-forum.com/t/error-private-method-gsub-called-for-symbol/71527/5 "2006-10-09T19:58:23Z")

</div>

On 10/9/06, Tanner B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > \<%= text\_field(:search,:city.gsub(/\s/, “‘’”)) %\>  
> > > standalone but in my app (inserted into a query) it comes out as such  
> > > do something like:
> 
> \<input type=“text” name=“city” value=“\<%=@search.city.gsub(/\s/,”‘’“)  
> %\>”/\>

Yeah, I’ve thought about this way but it would cause more problems for  
me  
later on.  
Seems though that when I put right before it goes into the select  
statement  
either AR or mysql is adding the backslahes for some reason.

Stuart
