工作在usrshow.html.erbWHERE条件不轨
<%= form_for userview_path, :method => 'get' do |f|%>
<%= f.collection_select :city, Place.all, :id, :name, :prompt => 'select place' %>
<%= text_field_tag :search %>
<%= submit_tag "Search"%>
<% end %>
在hotels_controller
def usrshow
if params[:search].present?
@hotels = Hotel.where(["city_id = ? and hotels LIKE ?",params[:city], "%#{params[:search]}%"])
else
@hotels = Hotel.all(:order => 'id DESC')
end
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @hotels }
end
end
我要搜索和显示酒店根据所选择的city.But这个代码不加工。
“不工作”是不够的信息。你有错误吗?这是什么意思“它不工作”? –
此代码未搜索字段。它只返回空字段 –
您是否在酒店表中有“酒店”或“名称”字段? – Debadatt