在 usrshow.html.erb
<%= 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
我必须根据所选城市搜索和显示酒店。但此代码不起作用。