Problem with fetching of data


#1

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.


#2

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


#3

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

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.


#4

Hassan S. wrote:

On Sat, May 23, 2009 at 11:09 AM, Santosh T.
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 :slight_smile:


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.!


#5

On Sat, May 23, 2009 at 11:09 AM, Santosh T.
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 :slight_smile:


Hassan S. ------------------------ removed_email_address@domain.invalid


#6

On Sat, May 23, 2009 at 12:49 PM, Santosh T.
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 :slight_smile:

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