Hi,
I was wondering what everyones favorite code shortcuts is?
i recently, thanks to this forum, came accross the power of constatize
and humanize. that alone cut down my long case statements that i was
writing in creating and building my instance variables to and from
views.
for example i used to have this
def getcat(category)
case category
when "cat1"
@myobj = Cat1.new
when "cat2"
@myobj = Cat2.new
....
....
end
now i can just do this right? this can handle all my case statements now
correct?
@myobj=category.humanize.costantize.new
also i like combining my if statements like
if @myobj.save and category == ''somehting'' then
do what ever
else
go to error paritial....works great when using validates
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---