We'll respond shortly.
eager-loading nested polymorphic associations
We have a controller action that performs n+1 queries to present associated models as nested hashes. The typical solution is to use :include to eager-load associations. Unfortunately, the models are related polymorphically, and :include can’t… Read more
"How can I know all the descendants of a class in the superclass at load time in ruby? I want to create a scope for each subclass."
"What popovers should I use?"
We've used at least these two before:
"What recurring billing system should I use?"
"pg gem version 0.12.2 seems to be leaving connections open sometimes after our application server is dead. This results in transactions that never finish. Anyone know what's up?"
require "psyche"; require "yaml"? WRONG! We've found you have to do them in opposite order or your parsing is "all screwed up".
"Rubymine is excluding code in our gem's
spec/directory from being indexed, can that be changed?"
We assume this is an optimization, because most people aren't interested in anything from a gem except the
lib/ directory. There doesn't appear to be a way to change this behavior.
"How can I override the gem version requirements on annoying gems in my project?"
We're trying to bring in
rails 2.3.2 +
rack 1.1.x, but rails explicitly requires the old version of the rack gem. Can we do something sneaky to change the requirements without forking and modifying the gem??
Backbone.js model support? Or maybe just straight
#to_json on models and embedding them into HTML templates?
"Is flash RTMP streaming a secure way to stream video so it can't be downloaded?"
We're using this with CloudFront + S3. But will it protect our content enough?
"RubyMine + rspec 2.6, why won't my focused tests run?"
We hoped this could be easily fixable by detaching the rspec gems and reattching them, but no luck with our usual fixes.
"MixPanel, is it a good tool for analytics and log analysis? "
Compared to normal analyics tools or splunk for log analysis?
"Anyone ever stubbed out 3rd party calls to a Thrift RPC service before?"
Is there a better solution than some sort of standard generic ruby stubbing & expectation tool?
update_attributecalls are not being persisted but no errors are generated.
net-ssh-telnetgem makes running a scripted batch SSH session pretty easy. This might be a good tool for you, if you want something much less complicated than capistrano or chef server for remote automation.
belongs_toassociations can now automatically create back references each other, thanks to a Backport of :inverse_of from Rails 3 to rails 2.3.6. This allows us to keep our object graphs more correct and avoid situations where we have 2 copies of the same object because the object graph is walked in reverse. Here's how to use it:
class Parent < ActiveRecord::Base has_one :child, :inverse_of => :parent accepts_nested_attributes_for :child end class Child < ActiveRecord::Base belongs_to :parent validates_presence_of :parent end
"We keep getting webrat thread exceptions running our integration specs with the rails integration runner: Thread tried to join itself. The error message varies with different versions of ruby 1.8.6 vs 1.8.7."
Anyone had this problem or know why?
"How do I skin an iphone mobile site to be the correct width so it's not 980px wide?"
<meta name="viewport" content="width = device width" />
*"We're trying to deploy some nginx configuration changes to EngineYard Cloud, what's the right way to do that?"
We've tried building custom chef recipes to solve this problem, but they run after nginx has already restarted, so are a poor solution to this problem. The better solution might be to check in configuration files into the application and symlink them into the nginx configuration directory using a
before_symlink.rb hook in the
*"We've got a
has_manyassociation where some of the child records are originally saved in an invalid state. When we later load the parent and ask it if it's valid, it returns true even with
validates_associated. How can we get the desired validation behavior?"
Turns out that unloaded associations are not validated. Solution: load the association before calling
.valid? on the parent. In general, you should also not create invalid objects, instead using a state variable to put them into a "draft" or "incomplete" state where they are still valid but not complete. Then remove that state and you'll see the errors required to finish that object.
ids = [1,2,3,4,5,0] missing_ids = ids - Model.find_all_by_id(ids).collect(&:id)