where condition is not working in rails -


in usrshow.html.erb

<%= form_for userview_path, :method => 'get' |f|%>     <%= f.collection_select :city, place.all, :id, :name, :prompt => 'select place' %> <%= text_field_tag :search %> <%= submit_tag "search"%> <% end %> 

in hotels_controller

 def usrshow     if params[:search].present?         @hotels = hotel.where(["city_id = ? , hotels ?",params[:city], "%#{params[:search]}%"])         else         @hotels = hotel.all(:order => 'id desc')     end      respond_to |format|         format.html # index.html.erb         format.json { render :json => @hotels }     end end 

i have search , display hotels based on selected city.but code not working.

you don't need [] brackets in where:

@hotels = hotel.where("city_id = ? , hotels ?",params[:city], "%#{params[:search]}%") 

specify error. not working bad description

you can check sql query in console:

hotel.where("city_id = ? , hotels ?",params[:city], "%#{params[:search]}%").to_sql 

it show exact query. can run db , verify results.


Comments

Popular posts from this blog

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -