Ruby on Rails problems & solutions - Apr 12, 2011
Apr 12, 2011Why does my remote form only work the first time?
Why does my remote form only work the first time?
Thanks for all the follows and subscribes, based mainly on my Ruby and Rails problems and solutions series. Since it has proven to be so popular, I have created a new, specific Posterous site - ror4real, where this series will continue, on a (hopefully) more regular basis. First new post is up today.
RSpec view debugging hackI needed to see what the rendered view looked like, so I could figure out why it was finding “1151” instead of “1” in a tr>td selector. I knew how to do this in RSpec 1, but not in RSpec 2.
Handle divide by zero in select in OracleActually, I could do an entire blog entry, or even an conference session on the topic of avoiding the N+1 query problem when displaying data from legacy databases. Only in my case, it’s more like 7N+1. But, let’s just get down to today’s specific case. I needed to display a table of values, and I wanted to be able to sort the table on any of the columns. Sorting is most efficiently done by the database, no? But several of the columns were actually derived data, with simple calculations. You can still sort on such things, IF you create a custom column aka - “SELECT cola/colb as custom_column FROM …”. Unfortunately, if colb contains any zeros, the query will blow up. :-p
RSpec and weird error on stub and raise InvalidRecord
jQuery combobox Ever needed a combobox? I mean a real one (ie, you can type into it AND select items)? Here is an excellent blog, explaining the finer details of how it works: http://www.learningjquery.com/2010/06/a-jquery-ui-combobox-under-the-hood
RSpec’ing your rescue_from
Date Formats for Rails 3 It’s surprisingly difficult to find up-to-date, comprehensive info about date formats and time zones for Rails. It’s been a moving target, updated in every release. This thread pops up a lot:
Routes and formats For some reason, I got stuck on this. It’s not explicitly stated anywhere in the new routing documenation/guides, but if you need a format, it’s a parameter for your path: workbook_job_path(job, :format => ‘pdf’)