I want to convert the title of a page to a friendly URL and store it in the database as a permalink. My problem is I can't use the parameterize
method. It's not working. Other inflections are working like upcase
or downcase
but parameterize
is not working. Is there a special case for parameterize
?
This is my code:
Controller:
def create
params[:page][:permalink] = params[:page][:title].dup
@page = Page.new(params[:page])
end
Model:
class Page < ActiveRecord::Base
before_save :makeitpermalink
before_update :makeitpermalink
private
def makeitpermalink
permalink.parameterize!
end
end
According to the Rails' documentation, there is no bang (exclamation mark) version of the parameterize
method, so try removing it:
def make_it_permalink
self.permalink = self.permalink.parameterize
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With