AJAX Responses in JSON with Rails 2.1

In a recent task on my current project I was working on an ajax feature where i needed the response to be JSON. In my controller I was using the following to return the data in json format. However, in firebug it kept showing the response as text, not json. (Prototype 1.6.0 FWIW)

format.js { render :json => @parent.to_json(:include => :children)} if request.xhr?

the trick to solve this was to use the 'force' capability in the javascript as such:

new Ajax.Request(url, {
  evalJSON: 'force',
...
...
}
});

it took me some digging to get the answer for this.


Posted in ajax, ruby/rails | Tagged , , , , | Leave a comment

Recent twitter posts

Powered by Twitter Tools.

Posted in misc | Leave a comment

Phusion Passenger on MacOSX

A quick run-down on how to get up and running with Phusion Passenger and you existing rails application on MacOSX.

  • Grab the passenger gem:
    sudo gem install passenger
  • Grab the pref pane utility. Note: OSX 10.5.2 or later is required for this pref pane utility.
    http://superalloy.nl/misc_files/passenger_pane/PassengerPane-1.1.tgz
    (thanks to Eloy for building this useful utility). Extract and install using typical mac software installation steps.
  • Additionally you can view the github repo for passenger_pane at: http://github.com/alloy/passengerpane/tree/master
  • Edit your apache configuration (assuming you are using the default apache2 from apple, not macports) as follows:
  • Add the following lines to /etc/apache2/users/.conf (assuming your path information is the same, otherwise please change to reflect your local environment).LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
    PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.0.3
    PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  • Fire up the pref pane, drop your app directory in the box as requested (see screenshot) and poof, you are on passenger.

If you have any problems, check the README in at the github repo mentioned above which provides more details for non-standard pre-requisites.


Posted in misc | Tagged , | Leave a comment

MythTV, SA3250 HD Cable box and PCHDTV 5500 tuner card for linux

After converting to a mac almost a year ago I was left with a surplus linux server that had previously been my 'workhorse' machine. I decided to convert it to a media server. I was interested in HD television via tuner cards for a computer-based 'media center' eliminating the need for another lcd tv.

My configuration is as follows:

  • AMD64 X2 4200
  • 2x80gb SATA hard drives
  • 1x300gb external (usb) freeagent drive
  • Ubuntu Hardy - 64bit
  • MythTV - latest version from the repos
  • PCHDTV 5500 tuner card for linux
  • Cox Communications digital cable service
  • Scientific Atlanta 3250 HD Digital cable box
  • SchedulesDirect Subscription for channel/program lineups ($20/yr)

Some of the problems I was forced to troubleshoot included:

  • Handling different sources of input from the tuner card and the cable box to get best resolution.
  • Handling the audio from the cable box versus analog cable line/inputs which included overcoming delayed, out of sync audio, and no audio at all.
  • Firewire connectivity between the mythtv box and the cable box

As I use this configuration I am certain i will be making changes in the near future. However, as time permits I plan to write a few more posts that cover these topics in detail if there is any interest.

Posted in audio/video | Tagged , | 2 Comments

Presenter Pattern in Rails

I took time to read more about the presenter pattern today. I came across an interesting post which included a few statements that were very compelling:

?The first advantage we gain is that we can unit test view logic easily.?
[ helps eliminate the the frailty of view testing to some degree]

?Secondly, we can move all helper methods into presenters so that we can have a more elegant way to implement these methods.?
[ this seems great because their tends to be either excessive code in helpers in many projects i see or not enough (correct) code in helpers.]

?The third and the most important advantage we gain is that now the model is free from view logic, making its intention much more clear.?
[ who wouldn't want this?]

Posted in ruby/rails | Leave a comment

Clips - a very ‘mac’ way to deal with clipboard fragments

I?ve been a user of Conceited Software?s Linkinus IRC application ever since it was first released and love it. Very classy. Now they have applied the same shine to another application that deals with managing the clipboard.

Clips provides a nice usability experience for this type of work. I am just starting to use it but it seems impressive. Pricey but if it really helps me manage the mess of information i deal with, well worth it.

Posted in apple, productivity, software | Tagged | Leave a comment

Textmate - fix filetype recognition issues with RSpec and Rails bundles.

Over time i have collected several ruby related textmate bundles which i have enjoyed tweaking for easier usage. During this time I somehow managed to mangle my file type recognition settings. I first noticed this problem by losing the ability to use the shortcut keystroke to execute rspec tests.

The solution lies in this textmate blog post: http://blog.macromates.com/2007/file-type-detection-rspec-rails

In summary i did the following:

Closed textmate completely and deleted the related manual textmate bindings for these languages with the following command in the terminal:

defaults delete com.macromates.textmate OakLanguageFileBindings

Next I changed the way textmate viewed ownership of the .rb file extension. I specifically revoked it from the Ruby bundle and enforced the ownsership in the RubyOnRails bundle.

Opened textmate and navigate to Bundles -> Bundle Editor -> Edit Languages and added rb to the Ruby on Rails grammar's fileTypes array so that it reads:

fileTypes = ( 'rb', 'rxml', 'builder' );

Note: These are the values in my RubyOnRails language settings. Yours may differ but the important entry is 'rb'. Make sure its included in the list.

Next, I navigated to the Ruby Bundle -> Language settings in similar fashion and REMOVE the 'rb' file type from the list. There was a large amount of text to sort through in looking for this setting so i simply copied all to a text window, searched and replaced then pasted back into the textmate language definition window.

At this point the filetypes were registering fine for rspec tests and ruby/rails filetypes. I checked this by watching the status bar - filetype setting display.

Posted in software | Tagged , | 1 Comment
Copyright 2008 brightpoint | Powered by WordPress. Built on the Thematic Theme Framework.