Answer the question
In order to leave comments, you need to log in
How to make URL with date like on Meduza?
How to make a URL like this https://meduza.io/feature/2016/10/11/sgorevshiy-fl... ?
Answer the question
In order to leave comments, you need to log in
The to_param method in the ActiveRecord model is responsible for generating the url.
For the meduza example, the to_param method would look something like this
class Article < ...
# ...
def to_param
"#{created_at.year}/#{created_at.month}/#{created_at.day}/#{transliterated_title}"
end
# ..
end
def to_param
"#{created_at.year}/#{created_at.month}/#{created_at.day}/#{id}-#{transliterated_title}"
end
def to_param
"#{created_at.year}/#{created_at.month}/#{created_at.day}/#{transliterated_title}-#{id}"
end
before_save :update_slug
private
def update_slug
self.slug = to_param
end
def to_param
"#{id}-#{transliterated_title}"
end
form part "sgorevshiy-flagman...." will help gem friendly id
About the date this should help
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question