RailsCasts Pro episodes are now free!

Learn more or hide this

Rob Jones's Profile

GitHub User: craic

Site: http://craic.com

Comments by Rob Jones

Avatar

I'm running postgresl 9.2.1 on Mac OS X, installed by homebrew and Rails 3.2.12

The postrgresql lib directory has unaccent.so

But it is not installed by default and Ryan's migration did not seem to do anything.

What worked for me was:

bash
$ rails db
my_db=# create extension unaccent;
my_db=# \dx
                         List of installed extensions
   Name   | Version |   Schema   |                 Description
----------+---------+------------+---------------------------------------------
 plpgsql  | 1.0     | pg_catalog | PL/pgSQL procedural language
 unaccent | 1.0     | public     | text search dictionary that removes accents
Avatar

Typo in the /app/controllers/comments_controller.rb code block in 'Read the episode'

@commentable = resource.singularize.classify.contantize.find(1)

... missing the 's' in constantize

Avatar

A minor update is required for sunspot_rails 1.3.3 (rails 3.2.6)

$ rake sunspot:solr:start
  Note: This task has been moved to the sunspot_solr gem. To install, start and
  stop a local Solr instance, please add sunspot_solr to your Gemfile:

  group :development do
    gem 'sunspot_solr'
  end

The rake task remains the same after this change

Avatar

In general I find using a csv view template to be more useful that a to_csv method in a model.

The problem with the view template is that the file will be downloaded with the last component of the URL as the name.

For example from a Show action with a URL like /posts/2.csv you'll get a file called 2.csv, which is not very friendly

Clinton Nixon has a nice solution in this stackoverflow post

http://stackoverflow.com/questions/94502/in-rails-how-to-return-records-as-a-csv-file

He creates a render_csv method in the application controller that adds headers to the response that use either the user supplied filename or defaults to the action name

For example, this produces a file called 'myfile.csv'

ruby
   respond_to do |format|
      format.html
      format.csv {
        render_csv('myfile')
      }
  end 
Avatar

Numbers '09 version 2.1 (436) ... should be the latest (did you transpose 1 and 2?)

Avatar

Keep in mind that Excel XML output is not readable by Apple Numbers.

Numbers will display the raw XML. It will take the older 'native' Excel format.

Come on, Apple, I want to like the program but the last update was 2009...

Avatar

This is a very nice solution when the number of entries is small. But when that number grows and/or you are not sure what options are available, a good alternative is to use two select menus in tandem. You populate the second from the first and can fine tune that list before submitting.

There are a number of jQuery solutions for doing this. I just posted one last week and hope to have an example Rails helper in the next day or two.

http://craic.github.com/tandem_select_jquery_plugin/