【发布时间】:2014-04-06 12:40:16
【问题描述】:
我有三个模型Lcities 和lservices 和search
class Lcity < ActiveRecord::Base
has_many :Lservices
attr_accessible :lname , :lcode , :lexperience , :lrating , :llocation
end
和
class Lservice < ActiveRecord::Base
belongs_to :Lcity
attr_accessible :lcode , :lscode , :lcharg , :lname
end
class Search < ActiveRecord::Base
attr_accessible :city , :services
end
在Search form 中提交后,我想要 Lcities 模型中的所有 lname,我知道 sql 查询但如何在 Rails
>select lname from Lcity where llocation.Lcity = lname.Lservice
form_for search
<%= form_for (@search) do |f| %>
<%= f.select(:city, city_for_select, :prompt => 'Select City') %>
<%=f. select(:service, service_for_select, :prompt => 'Select Services') %>
<% end %>
【问题讨论】:
标签: ruby-on-rails search full-text-search html-select