Topic: Converting input from text_field to upper case

I am taking a 5 letter input from the following form statment:
         
   <%= text_field 'link', 'graph', {"size" => 5} %>

..and passing it to this controller statement:

   @link = Link.new(params[:link])

I want to convert the input automatically to upper case. I have been trying to add ".upcase" to the link parameter but keep getting errors.

What is the best way to use upcase in this scenario?

thanks

john

Re: Converting input from text_field to upper case

Easiest way is probably this

params[:link][:graph].upcase! if params[:link][:graph]
@link = Link.new(params[:link])

note the '!' on the end of upcase, that says make that string uppercase in place, 'upcase' without an exclamation point returns a copy of the string and keeps the original as is. You possibly used 'upcase' (no '!') and without realizing it saved the original and not the copy.

probably the "correct" way to do this is with before_create. In your model add

before_create :upcase_graph

def upcase_graph
   self.graph.upcase! if self.graph
end

Re: Converting input from text_field to upper case

That worked perfectly!   Thanks so much for the help, Tortoise.

I guess my real problem is that I still don't understand the correct naming conventions for objects. I'm going to have to go back to the basics and fill in my foundation.

Time to hit the books!

seeya

jackster