Archive for April, 2008

graphs with rails

[nuby on rails article on gruff)[http://nubyonrails.com/pages/gruff]

Autocomplete in rails 2.0

The way to do autocomplete in rails 2.0 is to use a plugin. The text_field_with_auto_complete feature is deprecated.

Do script/plugin install auto_complete

It?s also here

The plugin seemed to have some issues (as in it DID NOT work). This guy had a good fix which I copy and pasted over the standard file in my lib folder of plugin, and here?s where I linked off from. The issue seemed to be related to the protect_from_forgery key.

auto-complete on belongs_to association

multiple text-fields with auto-complete

Rescue - how to supress a nil NoMethodError

This is pretty easy, but I always seem to forget (see comment):

             <%= @post.author.name rescue "no author" -%>

How to include a lib file in your environment.rb

Give the file a name in the lib folder and then in the environment.rb file do a: require ?libfilename?

simple, huh?

Full text searching in rails

Use acts_as_ferret

I had serious trouble with adding conditions to acts_as_ferret in order to query only for a certain user_id. You have to do the following with the little {}

            @records = Record.find_by_contents params[:search], {}, {:conditions => ["user_id = ?", current_user]}

And to run it on a production server - go here

Pagination in Rails 2.0

Rails 2.0 pagination - it?s best to go ahead and use the will_paginate plugin

this is the most up to date - April 4th, 2008. He moved it to a git repository or his github

Ryan is also on it

You can also combine it with a simple search form - see Ryan?s episode 37 though this won?t be too hot for most things. You need full text search. For that possibly use acts_as_ferret

Here?s the documentation

Rails 2.0 link_to_remote, RESTful routes link_to_remote

To get link_to_remote to work on rails 2.0 / RESTful routes, you need to add :method => :get to link_to_remote. For example

            <%= link_to_remote "e",
      :url => edit_record_path(record), :update => 'test', :method => :get %>

Rails 2.0 link_to_remote, RESTful routes link_to_remote

To get link_to_remote to work on rails 2.0 / RESTful routes, you need to add :method => :get to link_to_remote. For example

            <%= link_to_remote "e",
      :url => edit_record_path(record), :update => 'test', :method => :get %>

Lightbox with rails - use redbox

rb-lightbox-plugin

lightbox hellper

redbox

How to do date, datefields, datetime like 30boxes

The following are some links to do natural language date selection with rails. I recommend going ahead and using chronic, but take a look at Ryan Bates solution for good measure.

semi-solution - date-time-text-field-helpers

Ryan bates solution - this guy is the man

Ruby Chronic