I would like to create url bullets for tags controlled by act_as_taggable_on shortcut. For example, instead of URLs like http://myapp.com/tags/5 , I would like to have http://myapp.com/tags/my-tag (where "my tag" is the unique name of the tag) .
In models that I create myself, I usually do this by overriding the to_param model method and creating a โslugโ field in the model to save the result of the new to_param method. I tried to do this using the Tag ActsAsTaggableOn model, but it does not work.
Otherwise, I can override things in the tag.rb class ActsAsTaggableOn as follows:
# Overwrite tag class ActsAsTaggableOn::Tag.class_eval do def name n = read_attribute(:name).split n.each {|word| word.capitalize!}.join(" ") end end
However, if I try to override the to_param method in the same block with the method definition, for example:
def to_param name.parameterize end
Rails still generates and responds to routes with integer identifiers, not with a parameterized name. Actually in the console, if I try something like
ActsAsTaggableOn::Tag.find(1).to_param
An integer identifier is returned, not the result of an overridden to_param method.
I would prefer not to fork the gem and tune it if I can do this with my own application code. Thanks.
ruby-on-rails acts-as-taggable-on
Jamie forrest
source share