unable to query with friendly_id rails -


here controller

before_action :seo_url_product,only: :product  def seo_url_product     if params[:id]          @posts = post.friendly.where(sub_category_id: params[:id]).paginate(page:   params[:page], per_page: 2).to_a      end end 

here view

<% category.sub_categories.each |sub_category| %>     <li><%= link_to sub_category.name, controller: :posts, action: :product, id: sub_category %></li> <% end %> 

i can see friendly url when click sub_categories not see result.

i think problem trying query slug not real id. know friendly_id use slug. should find real id first try query.

insted of params[:id] in where query can use following.

sub_category_id = sub_category.friendly.find(params[:id]) # find id insted of slug @posts = post.friendly.where(sub_category_id: sub_category_id).paginate(page:   params[:page], per_page: 2).to_a 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -