Module: MakePermalink::Base
- Defined in:
- lib/make_permalink/base.rb
Instance Method Summary collapse
- #default_options ⇒ Object
-
#make_permalink(method, options = {}) ⇒ Object
Creates a permalink for a given object based on the method passed as parameter:.
Instance Method Details
#default_options ⇒ Object
24 25 26 27 28 29 |
# File 'lib/make_permalink/base.rb', line 24 def { :replace_non_ascii => true, :include_id => true } end |
#make_permalink(method, options = {}) ⇒ Object
Creates a permalink for a given object based on the method passed as parameter:
You can modify the default behavior with this two options
:include_id: This will include the objects id method. Default true. :replace_non_ascii: This will replace non-ascii-chars (like & and $) for their english words (and - dollars). Default true
class Post < ActiveRecord::Base
make_permalink :title
end
p = Post.create(:title => "Rock & Roll!")
p.permalink # => "1-rock-and-roll"
47 48 49 50 51 52 53 54 |
# File 'lib/make_permalink/base.rb', line 47 def make_permalink(method, = {}) define_method "permalink" do = self.class..merge!() # Remember to remove the trailing dashes! That's the last gsub "#{self.create_permalink_prefix([:include_id]).to_s + self.create_url_string(method, [:replace_non_ascii]).to_s}".gsub(/-$/, "") end end |