Ruby on rails 在rails中搜索select_标记?
我有三种型号Ruby on rails 在rails中搜索select_标记?,ruby-on-rails,search,full-text-search,html-select,Ruby On Rails,Search,Full Text Search,Html Select,我有三种型号Lcities和lservices和search class Lcity < ActiveRecord::Base has_many :Lservices attr_accessible :lname , :lcode , :lexperience , :lrating , :llocation end 用于搜索的表单 <%= form_for (@search) do |f| %> <%= f.select(:city, city_for_sel
Lcities
和lservices
和search
class Lcity < ActiveRecord::Base
has_many :Lservices
attr_accessible :lname , :lcode , :lexperience , :lrating , :llocation
end
用于搜索的表单
<%= form_for (@search) do |f| %>
<%= f.select(:city, city_for_select, :prompt => 'Select City') %>
<%=f. select(:service, service_for_select, :prompt => 'Select Services') %>
<% end %>
“选择城市”)%%>
“选择服务”)%%>
首先,您的符号必须向下显示:
has_many :lservices
及
其次,您的SQL是从右到左的。。。而且,这几乎毫无意义。但是,为了满足custommer的要求,它应该是(注意表的复数形式):
对于您的查询:
Lcity.joins(:lservices).where("lservices.lname = lcites.llocation")
不确定你期望得到什么样的结果,但答案与你的问题相符
has_many :lservices
belongs_to :lcity
select lname from lcites,lservices where lcites.llocation = lservices.lname
Lcity.joins(:lservices).where("lservices.lname = lcites.llocation")