Archive for May, 2012

30
May
12

rails translating attribute names

I found the answer to my question from here.
Here’s the way:


  activerecord:
    attributes:
      user:
        first_name: "Name first"

Advertisements
22
May
12

making sure your integration tests view the actual data in the db


Monkeypatch ActiveRecord with this:


class ActiveRecord::Base
  mattr_accessor :shared_connection
  @@shared_connection = nil

  def self.connection
    @@shared_connection || retrieve_connection
  end
end

and your spec_helper with this:


RSpec.configure do |config|
  config.use_transactional_fixtures = false

  config.before :each do
    if Capybara.current_driver == :rack_test
      DatabaseCleaner.strategy = :transaction
    else
      DatabaseCleaner.strategy = :truncation
    end
    DatabaseCleaner.start
  end

  config.after do
    DatabaseCleaner.clean
  end
end

Full info available on Nicholas Rutherford’s blog. Thanks Nicholas!

22
May
12

rails select only some columns


If you want to only select a few columns on a query, here’s how you can do it:

 YourModel.find(:all,:select => "column1,column2") 

09
May
12

adding coffeescript support to sublime text 2 in ubuntu

Download Sublime, and start it one time, so that it creates the ~/.config/sublime-text-2 folder. chdir to ~/.config/sublime-text-2/Installed Packages and run:

git clone git://github.com/jashkenas/coffee-script-tmbundle CoffeeScriptBundle.tmbundle

Restart sublime, and now coffeescript syntax highlighting will work.




Blog Stats

  • 228,094 hits