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.
11bbca99cea0c2f3de8cd6de4d20e2d9?d=identicon&s=25 Santosh Turamari (santuhvr)
on 2009-05-23 10: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.
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-05-23 19: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 Turamari <rails-mailing-list@andreas-s.net>
11bbca99cea0c2f3de8cd6de4d20e2d9?d=identicon&s=25 Santosh Turamari (santuhvr)
on 2009-05-23 20:09
Colin Law 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 Turamari <rails-mailing-list@andreas-s.net>

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.
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2009-05-23 20:21
(Received via mailing list)
On Sat, May 23, 2009 at 11:09 AM, Santosh Turamari
<rails-mailing-list@andreas-s.net> 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 Schroeder ------------------------ hassan.schroeder@gmail.com
11bbca99cea0c2f3de8cd6de4d20e2d9?d=identicon&s=25 Santosh Turamari (santuhvr)
on 2009-05-23 21:49
Hassan Schroeder wrote:
> On Sat, May 23, 2009 at 11:09 AM, Santosh Turamari
> <rails-mailing-list@andreas-s.net> 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 Schroeder ------------------------ hassan.schroeder@gmail.com


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.!
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2009-05-23 22:21
(Received via mailing list)
On Sat, May 23, 2009 at 12:49 PM, Santosh Turamari
<rails-mailing-list@andreas-s.net> 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 Schroeder ------------------------ hassan.schroeder@gmail.com
This topic is locked and can not be replied to.