Search on select_tag in rails? -
i have 3 models lcities
, lservices
, search
class lcity < activerecord::base has_many :lservices attr_accessible :lname , :lcode , :lexperience , :lrating , :llocation end
and
class lservice < activerecord::base belongs_to :lcity attr_accessible :lcode , :lscode , :lcharg , :lname end class search < activerecord::base attr_accessible :city , :services end
after submitting in search form
want lname
lcities model know sql query how apply on rails
>select lname lcity llocation.lcity = lname.lservice
form_for search
<%= form_for (@search) |f| %> <%= f.select(:city, city_for_select, :prompt => 'select city') %> <%=f. select(:service, service_for_select, :prompt => 'select services') %> <% end %>
to start with, symbols have downcased:
has_many :lservices
and
belongs_to :lcity
second, sql right-to-left... also, makes little no sense. however, satisfy custommer, should (mind plural tables):
select lname lcites,lservices lcites.llocation = lservices.lname
for query:
lcity.joins(:lservices).where("lservices.lname = lcites.llocation")
not sure kind of results you're expecting, answer matches question.
Comments
Post a Comment