Rails acts as taggle on filter by multiple tags

前端 未结 1 903
花落未央
花落未央 2021-01-03 15:18

I have a model, Tasks, that can be tagged with the acts as taggable on gem.

The route: get \'mainpage/:tag\', to: \'mainpage#index\', as: :tag

Right now

相关标签:
1条回答
  • 2021-01-03 15:42

    From http://guides.rubyonrails.org/routing.html section 3.11:

    get 'mainpage/*tags, to: 'mainpage#index', as: :tag
    

    Adding this route allows you to have URLs like /mainpage/bills and /mainpage/bills/tv/furniture.

    The first URL would come into your mainpage#index method with params[:tags] == 'bills', while the second one would come in with params[:tags] == 'bills/tv/furniture'. You could then simply split params[:tags] on /.

    Note, for seo purposes, you probably want to come up with some nomenclature for the URLs, i.e. the tags are always alphabetical in the URL or something like that.

    0 讨论(0)
提交回复
热议问题