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