Tuesday, August 31, 2010

NoMethodError: undefined method 'coordinates' for #

In trying to use the latest Sunspot code (from github) for geo search with Rails 3.0.0 , I was getting the following error while running Sunspot.index!(Location.all), where Location is my ActiveRecord class for storing locations:

After searching through the new code I found that coordinates is no longer a valid field type, but instead location is to be used. location expects an object that responds to lat and lng. Sunspot provides a handly little struct called Coordinates to be this object. So, here is my model code for setting up the search:

notice the virtual attribute called coordinates which wraps the lat & lng ActiveRecord attributes. My search code now looks like this:

And my search results are coming in as expected.

Tuesday, August 10, 2010

Rails 3 doesn't like auto_link href_options

Even though the Rails doc indicates one should be able to do something like this:
auto_link(simple_format(h(text)), :href_options => { :class => 'auto-link' })
it doesn't work. looking at the Rails code in text_helper.rb, auto_link is only looking for options[:html], so :href => {} just gets ignored. one actually needs to do this:
auto_link(simple_format(h(text)), :html => {:class => 'auto-link'})
and now it works fine.

Monday, August 9, 2010

jquery auto resize fonts

I ran experiments on font-size versus line length so that I could find the proper formula to automatically resize a font in order to keep the character count per line the same as a person resizes his browser window.
UPDATE: i inverted the resize function to look traditionally linear.
Here is the jquery code that keeps the line length the same:it works pretty well with Chrome and Safari on Mac.
the initial inspiration for this code came from a post by ingeva on daniweb.

font size versus line length

I ran an experiment on Google Chrome (code below) to determine how line length varied with font size. it looked pretty linear.

Below is my guess for the curve. You can see it on Wolfram Alpha:
(line length) = 25.407 * (font size) + 6.3799

Here is the jquery/html code i used to generate the results:
the initial inspiration for fitting the curve of font size to line length came from a post by ingeva on daniweb.

Monday, August 2, 2010

NoMethodError: undefined method sanitize_for_mass_assignment

once upon a time i started getting a strange error:

NoMethodError: undefined method `sanitize_for_mass_assignment'

after poking and prodding it turned out that after running bundle install, bundler grabbed the latest version of the state_machine gem, namely 0.9.4, which makes the call to sanitize_for_mass_assignment, which wasn't found. i likely have some other dependencies missing. however, to get back to my regularly scheduled coding, i just modified my Gemfile to use a previous version of state_machine:

gem 'state_machine', '0.9.3'

now all is good and my rake tests are passing again.