lundi 7 mars 2016

How to dispaly category name

i want to display the search item name in search page as heading. (here it is displaying value instead of name)

I am searching through ransack.

My search view

<%= form_tag location_path, :method=>'get' do %> <%= select_tag :q, options_from_collection_for_select(Category.all, :id, :name, params[:q]), :class=>"btn1 btn-default1 dropdown-button1 dropdown-toggle"%> <input type="submit" value="SEARCH" class="btn1 home-search-button" > <%end %>

my search controller

def location q = params[:q] @key = q @property = Property.ransack(location_or_category_name_cont: q).result(distinct: true) end

MY location.html.erb

HERE IS WHERE I WANT DISPLAY THE PROPERTY NAME. as <h1>Properties in <%=@key%></h1> i am getting output like this.

enter image description here

BUT, instead of 2, I want to get output like this Properties in Residential. I have a category table with 3 category with fields id(1 ,2,3) and category_names (residential commericial and Finance.

Any help is appreciatable

Aucun commentaire:

Enregistrer un commentaire