Using rails 2.1.0 I have a really nasty bit of code in my controller in
my create action that i would like to move to my model:
params[:phrase][“word”] = params[:phrase][“word”].strip.squeeze(" ")
if params[:phrase][“word”] != nil
params[:phrase][“second_word”] =
params[:phrase][“second_word”].strip.squeeze(" ") if
params[:phrase][“second_word”] != nil
params[:phrase][“third_word”] =
params[:phrase][“third_word”].strip.squeeze(" ") if
params[:phrase][“third_word”] != nil
@phrase = Phrase.new(params[:phrase])
What would be the best way to do this, I was thinking of putting it
inside of a :before_save function. But i’ve never written one before and
didn’t know how to get the parameters from my recently saved phrase( how
do I tell it to use the phrase i just created? @phrase.word ? ). What
would you recommend??