jeudi 17 mars 2016

How to store location value as cookie in ruby on rails

I need to store the selected location value as a cookie value.

I have a Location and Property table , I fetches and displays all locations from location table, so when a user clicks on this location it should search all properties related to that location.

Search is happening now, but problem is how to store the selected location value as a cookie value.

my layout page view.

<%= form_tag location_search_path, :method=>'get' do %> <%= select_tag :location_id, options_from_collection_for_select(Location.all, :id, :name, params[:q]), :class=>"btn btn-primary dropdown-toggle" ,:onchange=>'this.form.submit()'%><br> <% end %>

my search controller.

def location_search location=params[:location_id] @location = Location.find(location).name if params[:location_id].present? @property = Property.where(['location LIKE ? AND status=?', "%#{@location}%", '3']).all end

Please help.Any help is appreciatable

Aucun commentaire:

Enregistrer un commentaire