简体   繁体   中英

Query associations in rails

I have a 'countries' table. when i run a query in a controller action as " @country=Country.where(:name=>params[:location]) "

it says

' undefined method `where' for Country:Class ' it is working for my states and cites tables. Y so with countries table??

Do you have a Country model?

rails-app/app/models/country.rb

class Country < ActiveRecord::Base
end

A way to test if your Country model is working is:

$ rails console

> Country.all

Should show you all the records in your countries table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM