You can use ActiveRecord callbacks: before_save :capitalize_title
def capitalize_title self.title = title.titleize end Here are some more callbacks: http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html On Wed, Apr 30, 2014 at 9:42 AM, Megan Byrne <[email protected]>wrote: > Hello all, > > I'm relatively new to RoR and have a quick question. > > I want to make sure that the :title of wikis that are submitted through a > form are always converted to capital letters so that they can be sorted > properly. Currently they are sorted alphabetically, but this becomes a > problem if people do not capitalize their first letter (ie. uppercase > letters sorted first, then lowercase sorted next). > > I know that I want to do something like wiki.title.titleize, which is a > great RoR extension, but where do I put this? Is it something I write into > the create and update methods in the controller? Or, is it something I > write in the model? > > > -- > -- > SD Ruby mailing list > [email protected] > http://groups.google.com/group/sdruby > --- > You received this message because you are subscribed to the Google Groups > "SD Ruby" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- -- SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby --- You received this message because you are subscribed to the Google Groups "SD Ruby" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
