How to use parameterization in Rails?

I want to convert the page name to a friendly URL and save it in the database as a permalink. My problem is that I cannot use the parameterize method. This does not work. Other kinks work like upcase or downcase , but parameterize does not work. 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 
+6
ruby-on-rails
source share
1 answer

According to the Rails documentation, there is no hacking method (exclamation mark) for the parameterize method, so try removing it:

 def make_it_permalink self.permalink = self.permalink.parameterize end 
+9
source share

All Articles