if products.nil?
products.first.total_amount
else
0.0
end
There is a cleaner way to achieve the same result:
products.first.try(:total_amount) || 0.0
passionate hackers in Hong Kong. Agile, Ruby On Rails, Scala and Pen Test
if products.nil?
products.first.total_amount
else
0.0
end
products.first.try(:total_amount) || 0.0
configatron.apn.cert = File.join(Rails.root, 'config', 'certs', 'apn_dev.pem')
configatron.apn.cert = File.read(File.join(Rails.root, 'config', 'certs', 'apn_dev.pem'))
device = APN::Device.find_or_create_by_token(apn_token)
device = APN::Device.find_or_create_by_token_and_app_id(self.apn_token, apn_app.id)
00ea74e76a873e8e9c14c2dd2afe3b42abb35148e94042811e2b6985072641f2
00ea74e7 6a873e8e 9c14c2dd 2afe3b42 abb35148 e9404281 1e2b6985 072641f2
worker: bundle exec sidekiq -e production -C config/sidekiq.yml
worker: bundle exec sidekiq -e $RACK_ENV -C config/sidekiq.yml
Errno::ENAMETOOLONG
WARN: File name too long - Bag Attributes
Padrino.before_load do Mongoid.load!(File.join(Padrino.root,"config/database.yml")) end
Mongoid.load!(File.join(Padrino.root,"config/mongoid.yml"))
yesterday Thomas shared about MVC4 (beta) at Codeaholics
he did a demonstration on generating a new CRUD web application and a set of HTTP web API.
it was nice !
it just copied most of the tools/design from Ruby On Rails and the IDE is even better than those for Rails.
although the controller code is still too verbose
and the community to build library (gems) is not as active as Ruby one
but it is really a good move for Microsoft developers (most of them get stuck in the big enterprisy company, learning nothing new except politics) to know more about the best practices to develop Web application
Another funny thing was that ... Jacob was sharing about Play and the code base turned out to be so similar to those written by Thomas !
yes ! the syntax of Scala on Play and .Net on MVC4 was so similar
Both framework picked a lots of popular features/design from Ruby On Rails and it is good ! more and more best practices being found and recognized by all the coding community. It makes software better and coders are easier to pick up another tech stack.
Thanks all the speakers !
special thanks to Jacob who was just visiting Hong Kong and spent some time sharing coding things with our local community !
this post is based on
http://www.christopherirish.com/2011/09/02/ruby-1-9-2-segmentation-fault-and-openssl/
every ruby developer must have seen "Segmentation fault" when they run rake tasks, install gems or updating gems. The usual reason is because of the depending libraries are not updated or using the wrong one during the setup of ruby runtime.
very often it is because of openssl or iconv. To fix that error, you have to re-install your ruby runtime. If you are using rvm, these are the commands to uninstall and reinstall everything with correct libraries:
rvm remove 1.9.3
rvm pkg install iconv
rvm pkg install openssl
rvm install ruby-1.9.3 --with-openssl-dir=$rvm_path/usr --with-iconv-dir=$rvm_path/usr