rails assets pipeline “Cannot allocate memory – nodejs”

It’s simple to spend the three minutes (maybe two if you type fast) to add a swap file to your server. If you’re running Ubuntu (not sure how well this works for other Linux flavors), just follow this tutorial from DigitalOcean: https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04 Voila!

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

What is the purpose of vendor/bundle? Heroku tells me to remove it

If you have the vendor/bundle directory in your project then at some point you must have run the bundle command with the –path vendor/bundle argument. This will load the files for all your project’s gems (listed in Gemfile) into the vendor/bundle directory in your local project rather than to a system gem location. You would … Read more

How to use Eclipse for Ruby on Rails (RoR)

To save you some legwork, in Eclipse: Go to Help -> Install New Software… Click add (top right of popup) Enter a Name like “RadRails2” Enter the location as http://download.aptana.com/tools/radrails/plugin/install/radrails-bundle (for the full Aptana studio Studio 3, instead enter http://download.aptana.com/studio3/plugin/install) Click ok Restart Eclipse Go to Window -> Preferences. You will see Ruby is enlisted … Read more

Rails – How to test that ActionMailer sent a specific attachment?

Here’s an example that I copied from my rspec test of a specific attachment, hope that it helps (mail can be creating by calling your mailer method or peeking at the deliveries array after calling .deliver): mail.attachments.should have(1).attachment attachment = mail.attachments[0] attachment.should be_a_kind_of(Mail::Part) attachment.content_type.should be_start_with(‘application/ics;’) attachment.filename.should == ‘event.ics’

Gem Vs Plugin Vs Engine in Ruby on Rails

Plugins as you knew them from Rails 2 (i.e. plugins under the vendor/plugins folder) were deprecated for Rails 3.2; support for it was completely removed in Rails 4. Now, there’s a concept of a “gamified plugin” where the plugins are essentially built as gems and can be shared across different Rails applications. But to answer … Read more

How to save a model without running callbacks in Rails

I believe what you are asking for can be achieved with ActiveSupport::Callbacks. Have a look at set_callback and skip_callback. In order to “force callbacks to get called even if you made no changes to the record”, you need to register the callback to some event e.g. save, validate etc.. set_callback :save, :before, :my_before_save_callback To skip … Read more

what is the difference between link_to, redirect_to, and render?

link_to is used in your view, and generates html code for a link <%= link_to “Google”, “http://google.com” %> This will generate in your view the following html <a href=”http://google.com”>Google</a> redirect_to and render are used in your controller to reply to a request. redirect_to will simply redirect the request to a new URL, if in your … Read more

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