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 console is not outputting SQL Statements to my Development Log

the rails console never writes to the log file, but you can achieve it quite easily, for example, if you execute following after starting the rails console ActiveRecord::Base.logger = Logger.new STDOUT rails will log all SQL statements to stdout, thus display them in your terminal. and since Logger.new accepts any stream as first argument, you … Read more

Destroy/Remove database in Rails

By issuing rake -T you have the following database tasks: rake db:create # Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all dbs in the config) rake db:drop # Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases) rake db:fixtures:load # Load … Read more

Differences between railties and engines in Ruby On Rails 3

Railtie can probably do what you describe, but it may be more desirable to use an engine. The engine can have its own configuration and also acts like a Rails application, since it allows you to include the /app directory with controllers, views and models in the same manner as a regular Rails app. Read … Read more

What is the purpose of config.assets.precompile?

Most assets are automatically included in asset precompilation. According to the RoR Guide on the Asset Pipeline: The default matcher for compiling files includes application.js, application.css and all files that do not end in js or css: [ /\w+\.(?!js|css).+/, /application.(css|js)$/ ] You would use config.assets.precompile if you have additional assets to include: config.assets.precompile += [‘admin.js’, … Read more

Add association (

This should work in Rails 3.2 and Rails 4: post.association(:tags).add_to_target(Tag.first) See this gist: https://gist.github.com/betesh/dd97a331f67736d8b83a Note that saving the parent saves the child and that child.parent_id is NOT set until you save it. EDIT 12/6/2015: For a polymorphic record: post.association(:tags).send(:build_through_record, Tag.first) # Tested in Rails 4.2.5