Hi David,
I believe what you want is:
@zones = Zone.find(:all, :conditions => ["zone = ?", zone[:zone]])
If you type:
logger.debug(zone.inspect)
You will notice it is a hash with a key,value zone,100 (as you can see
from your parameters you sent: Parameters:
{"commit"=>"Search",
"zone"=>{"zone"=>"100"},
"action"=>"list",
"controller"=>"admin/zone"})
Good luck,
Tom
On 10/4/05, David Watts
<davewatts-ZYiLbvDUNhH9H04WiiaYkV6hYfS7NtTn@public.gmane.org>
wrote:> Hi All,
>
> Dumb question of the day. I have a mysql table called zones with a
> field named zone
> that I am trying to query. I have tried two different ways to get
> the text field input that
> I read in the rails book. I get ''--- \n- zone\n-
\"100\'' put into
> the query.
> I know this should be easy but I am befuddled.
>
> Thanks for any links to reference or suggestions
>
> The Table:
>
> CREATE TABLE `zones` (
> `id` int(11) NOT NULL auto_increment,
> `zone` int(11) NOT NULL default ''0'',
> `zone_name` varchar(50) NOT NULL default '''',
> PRIMARY KEY (`id`),
> KEY `zone` (`zone`)
> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT ;
>
> The Form:
>
> <%= start_form_tag :action => ''list'' %>
> <p><label
for="zone_zone">Zone</label><br/>
> <%= text_field (''zone'', ''zone'')
%></p>
>
> <%= submit_tag ''Search'' %>
> <%= end_form_tag %>
>
>
> def list
> zone = params[:zone]
> @zones = Zone.find(:all, :conditions => ["zone = ?",
zone])
> #and
> @zones = Zone.find(:all, :conditions => ["zone = :zone",
{:zone
> => zone}])
> end
>
> Gives me ....
> From Log:
>
> Processing ZoneController#list (for 127.0.0.1 at Tue Oct 04 14:46:01
> PDT 2005)
> Parameters: {"commit"=>"Search",
"zone"=>{"zone"=>"100"},
> "action"=>"list",
"controller"=>"admin/zone"}
> Zone Load (0.000889) SELECT * FROM zones WHERE zone = ''--- \n-
zone
> \n- \"100\"''
>
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>