Ask for Help
"Is there way to test if the Active Record associations you're trying to eager load with :includes are actually loaded?"
One solution would be to call .loaded on the proxy object which control the access to associations. Another would be to count the sql queries that the block of code makes.
Interesting things
When you query a table with a column containing string values, if you do Model.where(:string => 0) without using quotes for the 0, Rails will not to_s the 0 for you and the query will return the entire table.
We had a client project, a Rails 2 app, that needed some cleanup around JavaScript and CSS management. They were using both Sprockets 1 and Jammit, as well as a bunch of plugins and gems to help make all this work together. They had a set of problems that the Rails 3.1 Asset Pipeline solved. But due to gem dependencies we couldn't go to Rails 3 yet.
How hard could it be to put Sprockets 2 and the Asset Pipeline into a Rails 2 app?
Ask for Help
"What's the best way to deal with cross-window communication?"
It's done for now by having the Javascript constantly polling the server. Some other solutions could be using long-polling, websockets (to use websockets with Rails, EM-WebSocket seems to be a good solution). If you have a better answer, Matthew Kocher would be interested!
Interesting Things
"If you want to read remote files, the best way to do it is using GET requests."
One alternative would be to use run 'cat filename' which gives you a text output that you can store. But the issue with this option is that it will add control characters in your text which cannot be parsed and can consequently make everything blow up.
Hmmmmmm... Interesting!
Ever try really hard to get firebug working in your capybara window so you can sleep 1,000,000 in your test and play around on the console? If so, you can now use the "capybara-firebug" gem.
If you're trying to optimize your site for different mobile browsers, there's an emulator called "Ripple" that is magic. You can check out what it would look like on various screens, and if you happen to be using PhoneGap you can trigger events.
Normally, if you have a private method, you can't call it with an explicit receiver, even if that receiver is self. So you can't say
def foo
self.bar # explicit receiver
end
private
def bar
123
end
Instead, foo needs to call simply bar, leaving the self implicit:
def foo
bar # implicit receiver
end
However, when you call setters, you always need an explicit receiver, or you'll just assign a local variable:
def assign_things
self.a = 123
b = 456
end
def a=(v)
puts "This one gets called."
end
def b=(v)
raise "This one never does; the other method makes a local called `b` instead."
end
So, what do you do if you have a private setter? You call it with an explicit receiver:
def assign_things
self.a = 123
end
private
def a=(v)
puts "This is called successfully."
end
There's a crazy special exception in Ruby that lets you use an explicit receiver of self with a setter just so that you can call private setters.
This strikes me as weird. Why can't you call any private method explicitly on self? I thought it was just easier to implement Ruby if you couldn't, but if they made it work for setters, I'm not sure what the big deal is.
Ask for Help
"Is there a good way to manage SQL views using Active Record?"
Check out the rails_sql_views gem.
"Can I move a file or directory with git without having the history becoming disconnected (i.e have to use --follow)?"
Because of the way git stores files, this isn't really possible. One workaround is to use filter-branch to rewrite history to make it look like the file was never moved. However, you'd have to be careful and ensure that no one pushes the pre-filtered history to the repo after it has changed.
Interesting Things
"It's not possible to disable 1-click purchasing on a Kindle device."
Unless you want to have a long chat with your credit card company, make sure you keep this in mind before letting a niece / nephew borrow your Kindle :)
Ask for Help
"Is there anyway to prevent Capybara from resetting the session in RSpec?"
Capybara seems to have a reset_session_after_each option. It may or may not be useful.
Ask for Help
"Is there an easy way to white-label a domain when using SSL?"
Short answer: not really. One way would be to get a different IP and SSL certs. There are still some hurdles when sharing sessions across domains. Cookies can't be read across sites, either.
Interesting Things
- When deploying to Heroku using the Cedar Stack, BUNDLE_WITHOUT is not supported, but you can detect heroku in your Gemfile with ENV['HOME'].gsub('/','') == "app", and then substitute any group like staging/cucumber with "test" so they are not installed via the default bundle task on heroku.
- Rails 3 Asset Pipeline allows you to extend the compilation of additional files. Registering your own extension is easy but poorly-documented: you create a class that handles the compilation and register it with the asset pipeline.
Interesting
- Git 1.7.8 is out!
- We have a new gong in the office!
- When using
Timecop.timetravelin your tests, make sure that you use before setting up your test data. Otherwise the data could potentially be created before that time existed! git whatchangedgives you a normalgit logwith a list of changed files.
Help
- Rails console history is crazy! On opening a new session, and pressing up for history, random data appears from history, many eons ago. Two files are written to with each rails command -> irb_history and irb-history. Any idea what's going? Some people think that it might the interaction with wirble.
Ask for Help
"Has anyone used Heroku on a project with non-trivial scaling requirements?"
Yes. There have been several projects that scaled like magic by "sliding up the dynos".
Interesting Things
Michael Grosser announced "Venderor", a utility for managing vendored files à la Bundler. github
The SF office will be graced by the Kara's Cupcakes Truck distributing cupcakes and Blue Bottle Coffee; compliments of the building management company. Get a voucher at the front desk.
