Install gem stringex
Add following lines to Gemfilegem 'stringex', '~> 2.5.2' gem 'responders'Run command
# bundle install
Rails application have model Post with id:integer and title:string
class Post < ActiveRecord::Base acts_as_url :title, url_attribute: :slug def to_param "#{id}-#{slug}" end end
With config above, example: I have a post with id = 1 and title = "This is an example" then link to post look like
http://localhost:3000/posts/1-this-is-an-example
rubyonrails

0 comments:
Post a Comment