Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Friendly_id with two parameters?

I wonder if there's an easy way to use friendly_id and have two parameters instead of one, like this?

www.example.com/dateTitle/

date and title are two separate fields in my db.

like image 904
Philip Avatar asked May 07 '12 11:05

Philip


2 Answers

I know this question was made 2 years ago, but if it can help for future readers, friendlyId gem now integrates the 'candidates' funcionality that can help with this.

class Post < ActiveRecord::Base
  extend FriendlyId
  friendly_id :slug_candidates, use: :slugged

  def slug_candidates
   [
    [:created_at, :Title],
   ]
  end
end

More info in the gem repo.

like image 56
malditojavi Avatar answered Oct 06 '22 01:10

malditojavi


There sure is!

Just define a method on the model that formats the string before it gets slugged

Refer to this example: https://gist.github.com/2650300

like image 27
Matenia Rossides Avatar answered Oct 05 '22 23:10

Matenia Rossides