You can add the attributes to an array and then iterate over the same. In the loop use Object.attribute_present?(attribute_from_array) If this returns a true u have the value set for the given attribute for that object, else u update it.
eg :
A model book have following attributes : name, author, publish_date
Make an array : BOOKATTRIBUTES = [ 'name', 'author', 'publish_date']
Use the following loop:
BOOKATTRIBUTES.each do |attr|
if @book.attribute_present?(attr)
#don't set anything its already set.
else
# set the value of the attribute for the object
end
end
On Sat, Jan 9, 2010 at 6:19 PM, Quee WM <[email protected]> wrote:
> I have 34 boolean columns in my table related to a product.
>
> I need to present this information in a table format with the column
> header and the corresponding value set to yes or no depending on the
> boolean value. The end product (i.e. the resulting html code) will be
> sent as CDATA in an xml feed. and the same process will have to be
> repeated again for each product in the database table.
>
> What is the best way to test and then add the correct value without
> having to write 34 different if statements?
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
>
>
-- 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.

