On Jul 25, 2:32 pm, Hassan Schroeder <[email protected]> wrote: > On Mon, Jul 25, 2011 at 11:08 AM, Sandy <[email protected]> wrote: > > Since the params will give you either "0" or "1" as a string, and > > since you are trying to equate "0" (string) to "false" (boolean), why > > not set a variable equal to "true" or "false" based on the params? > > Or put something like this in an initializer: > -------------------- > class String > > def true? > ( self == "1" || self == "true" ) ? true : false > end > > def false? > !self.true? > end > > end > -------------------- > > Then you can more readably check e.g. params[:item][:status].true? > > FWIW, > -- > Hassan Schroeder ------------------------ > [email protected]http://about.me/hassanschroeder > twitter: @hassan
Or this may be helpful: def convert_to_boolean(value) return [true, "true", 1, "1", "T", "t"].include?(value.class == String ? value.downcase : value) end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

