Forum: Rails-core (closed, excessive spam) #713: Actionize && Parameterize. Thoughts?

Posted by Matt Darby (mdarby)
on 2008-07-27 17:06
(Received via mailing list)
I'm looking for some thoughts (and +1's!) on a patch (#713) that
introduces two new Inflectors: Actionize and Parameterize.
http://rails.lighthouseapp.com/projects/8994/ticke...


Actionize

Transforms a string in titleize() form to a string suitable for a
action name

   "Expense Report".actionize         # => "expense_report"
   "My Totally Cool Action".actionize # => "my_totally_cool_action"

   @reports = ['Expense Report', 'Employee Hours']
   @reports.each do |report_name|
     link_to(report_name, "/reports/#{report_name.actionize}")
   end
   # => "<a href = '/reports/expense_report'>Expense Report</a>
         <a href = '/reports/employee_hours'>Employee Hours</a>"

Parameterize

Replaces special characters in a string so that it may be used as part
of a 'pretty' URL.

==== Examples

   class Person
     def to_param
       "#{self.id}-#{self.name.parameterize}"
     end
   end

   @person = Person.find(1)
   # => #<Person id: 1, name: "Donald E. Knuth">

   <%= link_to(@person.name, person_path %>
   # => <a href="/person/1-Donald_E_Knuth">Login</a>


Thanks!

Matt Darby, M.S.
Rails | PHP | Linux | MySQL | IT

Email: matt@matt-darby.com
Skype: matt-darby
Web: http://blog.matt-darby.com
This topic is locked and can not be replied to.