There are several models:

class Product < ActiveRecord::Base extend FriendlyId friendly_id :name, use: :slugged belongs_to :material belongs_to :color end class Color < ActiveRecord::Base extend FriendlyId friendly_id :name, use: :slugged has_many :products end class Material < ActiveRecord::Base extend FriendlyId friendly_id :name, use: :slugged has_many :products end 

Suppose you choose one parameter in each:

 material: 'wood' color: 'gray' 

It is necessary to find all products with such values. And now the most interesting, it is necessary that the URL was not site.com/search?utf8=✓&..wood..gray , but site.com/wood/gray , and there was an opportunity to put the title , description and keywords .

I heard that you can somehow create a model for intersections, but did not understand.

    1 answer 1

    1. In routes.rb :

       get "(:material)/(:color)", to: "search#index", as: :search # search и index - твои контроллер и экшн соответственно. 
    2. In SearchController :

       @products = Product.where( color: Color.where(slug: params[:color]) material: Material.where(slug: params[:material]) ) 

    The disadvantage of this approach is that you cannot use multiple choice for material and color. Routes just will not miss.

    And yet, in order to switch to such beautiful URLs from the search form, you will need to conjure with JS before submitting, or redirect.

    But usually this does not bother. For search engines leave beautiful urla, and users are sent through search?... And on the page add link canonical .

    UPD:

    And how to set the title description keywords for the search result?

    You need to form them somewhere and then just add them to the layout. For example, in the same SearchController :

     def seo_data @color = Color.find_by(slug: params[:color]) @material = Material.find_by(slug: params[:material]) end 

    And then in app/views/layouts/<your-layout> add where you want the output of these tags. For example:

     <title>Диваны <%= @color.name %>, <%= @material.name %> купить, без смс. Без регистрации. Online.</title> 
    • And how to set the title description keywords for the search result? - ivl