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

How to assert the contents of an array, indifferent of the ordering

TL;DR The most direct way to check this is to sort the arrays before checking their equality. json.map{|d| d[“id”]}.sort.must_equal Database.all.pluck(:id).sort Still here? Okay. Let’s talk about comparing elements in an array. As it is, the map{} is already somewhat irrelevant to the test and adding clutter, I’d prefer to not add even more. Well, that … Read more

How do I see the ENV vars in a Rails app?

Assuming the staging environment, as your example points to. You’ll want to load the console by prepending the RAILS_ENV environment variable to the rails console command. RAILS_ENV=staging rails console That should get you in. Once you’re in, you can just access the ENV variable directly. 2.2.2 (main):0 > ENV And that will dump out the … Read more

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