私は時間ソースコードを読んでいて、そこにスラグSlugはRailsでどのように使用されますか?
https://github.com/DefactoSoftware/Hours/blob/development/app/models/concerns/sluggable.rb
と呼ばれるクラスがあると私はすべてのモデルは、文字列型とスラグと呼ばれる属性を持っている参照してください?
この場合、スラッグはどのように使用されますか?
以下のコードはtag
モデルの内部で使用スラグの一つであり、
class Tag < ActiveRecord::Base
attr_reader :total_hours
include Sluggable
validates :name, presence: true,
uniqueness: { case_sensitive: false }
has_many :taggings
has_many :hours, through: :taggings
has_many :projects, -> { uniq }, through: :hours
has_many :users, -> { uniq }, through: :hours
belongs_to :project
def self.list
Tag.order(:name).pluck(:name)
end
private
def slug_source
name
end
end
http://railscasts.com/episodes/314-pretty-urls-with-friendlyid ?view = comments これは、スラッグの実用的な使用例です。 – etusm
@Liシンヤン私の最後の編集を見てください。 – devoh