Forum: Ruby on Rails problem with fetching of data.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Santosh T. (Guest)
on 2009-05-23 12:05
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.
Colin L. (Guest)
on 2009-05-23 21:03
(Received via mailing list)
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>
Santosh T. (Guest)
on 2009-05-23 22:09
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.
Hassan S. (Guest)
on 2009-05-23 22:21
(Received via mailing list)
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 :-)

--
Hassan S. ------------------------ removed_email_address@domain.invalid
Santosh T. (Guest)
on 2009-05-23 23:49
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 :-)
>
> --
> 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.!
Hassan S. (Guest)
on 2009-05-24 00:21
(Received via mailing list)
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 :-)

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
This topic is locked and can not be replied to.