SyntaxHighlighter

Friday, January 22, 2010

Rails Autocomplete without Ajax (Autocompleter.local)


This was fun - though not easy to find the answer right away.

I wanted to add an autocomplete to a form, but I wanted the suggestions to be local (I didn't want to make any ajax requests, I wanted to use a pre-defined javascript array).

This ended up to real easy.

The scenario here - I have a nested set of objects that an admin may want to give membership privileges to an existing user in their system. The number of existing users, is low (< 100).

For this to work, I had a @member_emails variable accessible to the view. This held all the emails from members that were already members somewhere else in the system.

With this, admins are able to access existing users or add new users quickly.


<%= f.label :user_email, "User's email" %>
<%= f.text_field :user_email, :autocomplete => "off" %>
< div class="auto_complete" id="user_email_auto_complete" >< /div >

<%= javascript_tag("new Autocompleter.Local('membership_user_email', 'user_email_auto_complete', [#{ @member_emails.map{|e| "'" + e + "'" }.join(',') }] , {fullSearch: true, frequency: 0, minChars:1});") %>

Tuesday, January 12, 2010

RubyGem version error: rack(1.0.0 not ~> 1.0.1)

If you see this error - it may be due to the fact you installed Rails 2.3.5 a while ago and you do not have 1.0.1. Even after installing the latest rack gem, this error may persist.

Here are many people with the same issue

http://weblog.rubyonrails.org/2009/11/30/ruby-on-rails-2-3-5-released

I got around this by uninstalling rack and rails 2.3.5. When I reinstalled rails, it included the rack dependency.

Saturday, January 02, 2010

Adding Cron Jobs on Engine Yard

This is a bit hard to find on Engine Yard, but it's not tricky.

To get a cron job to run, you need to go to the Dashboard and click on 'crontab' for the running instance. This will show you all Scheduled Jobs - which is probably empty at this point.



In the "Run this command..." field, you want to enter something like this if you're going run a rake task:

cd /data/app_name/current && RAILS_ENV=production rake ns:run_task

This will change directory to the app in question and run the appropriate task from the right place.

Once you have the cron job in place, you need to 'deploy' one more time. Uncheck all your checkboxes and deploy. This won't overwrite your app, but will do other things that are needed to configure the cron job. This is also true if you delete a cron job.

There is currently no way to edit a cron job. You'll have to delete the job and recreate it with changes.