error: failed to build gem native extension when installing rails on mac mountian lion os

I see that you are using ruby 1.9.3 using rvm on OS X 10.8.2 (Mountain lion) It’s possible that some gems referenced by rails need gcc-4.2 in /usr/bin to build native estension. In Mountain Lion , even after installing Xcode 4.5 CLI tools ( opening the menu XCode – Preferences..Download -> Command Line Tools ) … Read more

RSpec testing redirect to URL with GET params

From the documentation, the expected redirect path can match a regex: expect(response).to redirect_to %r(\Ahttp://example.com) To verify the redirect location’s query string seems a little bit more convoluted. You have access to the response’s location, so you should be able to do this: response.location # => http://example.com?foo=1&bar=2&baz=3 You should be able to extract the querystring params … Read more

Rails: change column type, but keep data

A standard migration using the change_column method will convert integers to strings without any data loss. rake db:rollback will also do the reverse migration without error if required. Here is the test migration I used to confirm this behaviour: class ChangeAgeToString < ActiveRecord::Migration def self.up change_column :users, :age, :string end def self.down change_column :users, :age, … Read more

Rails database defaults and model validation for boolean fields

From here If you want to validate the presence of a boolean field (where the real values are true and false), you will want to use validates_inclusion_of :field_name, :in => [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # => true Or in Rails3 way validates :field, :inclusion => {:in … Read more

Full Text Searching with Rails

thinking_sphinx and sphinx work beautifully, no indexing, query, install problems ever (5 or 6 install, including production slicehost ) why doesn’t everybody use sphinx, like, say craigslist? read here about its limitations (year and a half old articles. The sphinx developer, Aksyonoff, is working on these and he’s putting in features and reliability and stamping … Read more

How to generate fixtures based on my development database?

The question is old, but as it still seems relevant: yes, there is an easy way to create fixtures from your development database: class ActiveRecord::Base def dump_fixture fixture_file = “#{Rails.root}/test/fixtures/#{self.class.table_name}.yml” File.open(fixture_file, “a+”) do |f| f.puts({ “#{self.class.table_name.singularize}_#{id}” => attributes }. to_yaml.sub!(/—\s?/, “\n”)) end end end Place this in a file in config/initializers – now you can … Read more

Provide params hash for put / post requests in rails console

If you want to put or post to a URL there are also methods for that. You can copy/paste the parameters exactly as they are displayed in your Rails production log: app.post(‘/foo’, {“this” => “that”, “items” => [“bar”, “baz”]}) app.put(‘/foo’, {“this” => “that”, “items” => [“bar”, “baz”]}) If you want to sent a custom header, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)