Rounding float in Ruby
Pass an argument to round containing the number of decimal places to round to >> 2.3465.round => 2 >> 2.3465.round(2) => 2.35 >> 2.3465.round(3) => 2.347
Pass an argument to round containing the number of decimal places to round to >> 2.3465.round => 2 >> 2.3465.round(2) => 2.35 >> 2.3465.round(3) => 2.347
You dont actually need to do this, so for people coming to view this question see: http://mongoid.org/en/mongoid/docs/rails.html “Unicorn and Passenger When using Unicorn or Passenger, each time a child process is forked when using app preloading or smart spawning, Mongoid will automatically reconnect to the master database. If you are doing this in your application … Read more
There is a Test::Unit “compatibility” module that comes with Minitest, so that you can (presumably) use your existing Test::Unit tests as-is. This is probably the Test::Unit module you are seeing. As of rails 3.2.3, generator-created tests include rails/test_help which includes test/unit. The test “something” do syntax is a rails extension. It’s defined in ActiveSupport::Testing::Declarative, which … Read more
Running the command below helped me somehow: rbenv exec gem install bundler
The update action (PUT method) is not appropriate because PUT is suppose to be idempotent. The only this would be possible is if the state was sent as part of the representation. This is inconsistet with an “event”. Is this correct? Correct. Since, events aren’t idempotent, then the a POST must be used. But, to … Read more
Yes, SSO using OAuth is a viable solution, but it’s not the simplest one. When building anything new, OAuth 2.0 is the way to go. The OAuth standards cover a lot of ground. The primary advantage of OAuth is that it allows users to give 3rd party apps access to their account without disclosing their … Read more
I switched from Mongrel Cluster to Passenger two weeks ago (Debian Linux Server). I didn’t look back for a second. Passenger is probably the easiest way to get your new server up and running. Performance and reliability are reasonable too. Personally, I like to spend my time working on exciting new Rails projects rather than … Read more
The simplest solution would be to create a module under lib and mix this into the models that need it, for instance, in lib/fooable.rb: module Fooable def do_foo end end And then in your various models: class MyModel < ActiveRecord::Base include Fooable end No need to require fooable.rb, the Rails autoloading mechanism will find it … Read more
According to this article you should add it. This will generate a bin directory in the root of your application. Make sure that it is not in your .gitignore file, and check this directory and its contents into git.
Use reject as in Model.find_all_by_xxx().reject { |r| r.something? }