ActiveRecord models localization

Suppose we have some model and we want to localize it, first of all we need to now i18n_key for that model. Open rails console rails c, and run:

OurModelName.model_name.i18n_key

For example let's do that for model, defined in public_activity gem:

PublicActivity::Activity.model_name.i18n_key
#=> :"public_activity/activity"

Now, we cat easily localize it, by adding this in .yaml file:

activerecord:
  models:
    public_activity/activity: 'Our localized model name'

In the same way we can locali...

Rails migration add float point field with scale and precision

class CreateFakes < ActiveRecord::Migration
  def change
    create_table :fakes do |t|
      t.decimal :float_value, :precision => 4, :scale => 3
    end
  end
end

This will allow you to have 3 digits after the decimal point and 4 digits max.

Rspec + Capybara + Rails4 + Spork (intergation tests setup with selenium and poltergeist)

Add in Gemfile:

group :development, :test do
  gem 'rspec-rails'
  gem 'spork-rails'
end

group :test do
  gem 'capybara'
  gem 'database_cleaner'
  gem 'email_spec'
  gem 'poltergeist'
  gem 'launchy'
  gem 'selenium-webdriver'
end

Run bundle install

Ensure your spec_helper.rb looks similar with this:

require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
# require 'spork/ext/ruby-debug'

Spork.prefork do
  # Loading more in this block will cause your tests to ...