# Problem with fetching of data

**URL:** <https://www.ruby-forum.com/t/problem-with-fetching-of-data/168638>\
**Category:** Rails\
**Created:** [May 23, 2009, 10:05am UTC](https://www.ruby-forum.com/t/problem-with-fetching-of-data/168638 "2009-05-23T10:05:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![santoshturamari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@santoshturamari](https://www.ruby-forum.com/u/santoshturamari)\
**Post date:** [May 23, 2009, 10:05am UTC](https://www.ruby-forum.com/t/problem-with-fetching-of-data/168638/1 "2009-05-23T10:05:56Z")

</div>

I want to know the number of ways in which I can fetch the data on a  
particular name from database, because I am getting invalid data, for  
the name with space such as “abc xyz”… It uses select \*from names where  
name=“abc-xyz”, whch is fetching wrong information, so please help  
me.And essentially I want to search on name itself rather than ID.

---

<div class="post-metadata">

**Author:** ![santoshturamari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@santoshturamari](https://www.ruby-forum.com/u/santoshturamari)\
**Post date:** [May 23, 2009, 7:03pm UTC](https://www.ruby-forum.com/t/problem-with-fetching-of-data/168638/2 "2009-05-23T19:03:47Z")

</div>

I think you need to provide more information for us to understand the  
problem (for me to understand it anyway). Can you post the code you are  
using to search for name “abc xyz” which is being turned into a query  
“abc-xyz” as that is very odd. If you could post an extract from the  
code,  
an extract from the log showing the query, and the table structure then  
someone may be able to work out what the problem is.

Colin

2009/5/23 Santosh T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![santoshturamari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@santoshturamari](https://www.ruby-forum.com/u/santoshturamari)\
**Post date:** [May 23, 2009, 8:09pm UTC](https://www.ruby-forum.com/t/problem-with-fetching-of-data/168638/3 "2009-05-23T20:09:51Z")

</div>

Colin L. wrote:

> I think you need to provide more information for us to understand the  
> problem (for me to understand it anyway). Can you post the code you are  
> using to search for name “abc xyz” which is being turned into a query  
> “abc-xyz” as that is very odd. If you could post an extract from the  
> code,  
> an extract from the log showing the query, and the table structure then  
> someone may be able to work out what the problem is.
> 
> Colin
> 
> 2009/5/23 Santosh T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

I am using this code.

* * *

In application\_helper

return url\_for :only\_path =\> false,:controller =\> ‘community’, :action  
=\> ‘search\_route’,:company =\>((company.downcase.strip.squeeze("  
“)).gsub(/[^[:alnum:]‘&’‘.’‘!’]/,‘-’)).squeeze(”-“).chomp(”-"), :id =\>  
id

* * *

In controller

def search\_route  
@query = " "  
if params[:company] != nil and params[:company] != “”  
@query = params[:company].strip  
#@query = “‘"#{@query}\*"’”

```
 @community = Community.find_by_name(@query)

```

…

* * *

here @community is fetching wrong information.

---

<div class="post-metadata">

**Author:** ![santoshturamari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@santoshturamari](https://www.ruby-forum.com/u/santoshturamari)\
**Post date:** [May 23, 2009, 9:49pm UTC](https://www.ruby-forum.com/t/problem-with-fetching-of-data/168638/4 "2009-05-23T21:49:30Z")

</div>

Hassan S. wrote:

> On Sat, May 23, 2009 at 11:09 AM, Santosh T.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I am using this code.  
> > In application\_helper
> > 
> > return url\_for :only\_path =\> false,:controller =\> ‘community’, :action  
> > =\> ‘search\_route’,:company =\>((company.downcase.strip.squeeze("  
> > “)).gsub(/[^[:alnum:]‘&’‘.’‘!’]/,‘-’)).squeeze(”-“).chomp(”-"), :id =\>  
> > id
> 
> Uh, you’re telling it to substitute a ‘-’ for white-space in the name;  
> if  
> that’s not what you want, don’t do it 🙂
> 
> –  
> Hassan S. ------------------------ removed\_email\_address@domain.invalid

Hi,  
Thanks for the reply… Here my main problem is I want to have only  
space between two words. Here if I use only company.downcase.strip, then  
it is taking '+'sign such as “abc+xyz”… I want it to be"abc xyz". Can I  
get the condition to produce the output of that kind.!

---

<div class="post-metadata">

**Author:** ![santoshturamari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@santoshturamari](https://www.ruby-forum.com/u/santoshturamari)\
**Post date:** [May 23, 2009, 8:21pm UTC](https://www.ruby-forum.com/t/problem-with-fetching-of-data/168638/5 "2009-05-23T20:21:21Z")

</div>

On Sat, May 23, 2009 at 11:09 AM, Santosh T.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am using this code.  
> In application\_helper
> 
> return url\_for :only\_path =\> false,:controller =\> ‘community’, :action  
> =\> ‘search\_route’,:company =\>((company.downcase.strip.squeeze("  
> “)).gsub(/[^[:alnum:]‘&’‘.’‘!’]/,‘-’)).squeeze(”-“).chomp(”-"), :id =\>  
> id

Uh, you’re telling it to substitute a ‘-’ for white-space in the name;  
if  
that’s not what you want, don’t do it 🙂

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![santoshturamari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@santoshturamari](https://www.ruby-forum.com/u/santoshturamari)\
**Post date:** [May 23, 2009, 10:21pm UTC](https://www.ruby-forum.com/t/problem-with-fetching-of-data/168638/6 "2009-05-23T22:21:16Z")

</div>

On Sat, May 23, 2009 at 12:49 PM, Santosh T.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for the reply… Here my main problem is I want to have only  
> space between two words. Here if I use only company.downcase.strip, then  
> it is taking '+'sign such as “abc+xyz”… I want it to be"abc xyz". Can I  
> get the condition to produce the output of that kind.!

Look at your gsub; if you want a space instead of ‘-’, it should be  
pretty obvious what to do 🙂

Open up irb and play with it a bit until you get the result you want:

irb(main):001:0\> (“abc  
xyz”.gsub(/[^[:alnum:]‘&’‘.’‘!’]/,‘-’)).squeeze(“-”).chomp(“-”)  
=\> “abc-xyz”

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid
