Use AJAX for onchange of a SELECT box

Here’s how to use AJAX from the onchange event of the SELECT element :

I used an extra ERB step in my view in order to reduce chaos being created by double quotes. This example actually triggers two AJAX calls on the event to update different targets (two cascaded SELECTs).

[html]
:model_select,
:url => { :action => :ajax_list_model_select },
:with=> ” ‘project_id=’+value”) + “;” +
remote_function(:update => :category_select,
:url => { :action => :ajax_list_category_select },
:with=> ” ‘project_id=’+value”)
%>

onchange_ajax } ) %>
[/html]

The result has the SELECT element with onchange=”new Ajax.Updater…”

Joy!

Happy Coding or Status Quo

… This presentation brought to you by Brains on Trains—The leading supplier of hosed-up thought processes.

Ok. Spent too big of a portion of last year FIGHTING with Micro$oft VS .NET 2003/2005 and trying desperately to show that my dying VB6 apps can be converted to them. Well, conversion doesn’t work, at least on my KLOC applications with major hacks embedded for unit testing and robust error handling.

Found the Rails in Feb 05 and basically “didn’t look back”. It took ‘till Nov 05 to get approval for the first app, and we were desperate. Success rate on that was HIGH as my off-the-cuff estimate “It’ll take 1 to 2 months” was right on target. Deployed critical-features version of app for public consumption at end of Nov. and then deployed final feature-rich (to the level that this rewrite needed) at end of Dec. Managers happy. Uesrs happy. Application admins (tech-support staff) happy. CODER HAPPY

I can’t say I”ve ever felt “Happy” coding in M$ anything. Always a catch, always a missing feature. Always a black box to deal with. Always some reason to spend 2 days googling and searching M$ forums for obscure answers.
Also, no support, unfriendly forum users, unhelpful forum “experts”.

I continue to hash around the balance between the pros and cons of this argument. It seems really clear on paper which is the better choice for continuing development… UNTIL the emotional ties to employer-loyalty, cost conciousness, time conciousness (both calendar time and timecard time) all get in the way. I have also voiced the concern to coworkers that with all the money M$ uses for VS development… how can it NOT be better??!!

In the final analysis, M$ CAN “not be better”. The 800lb Gorilla has lots of hair to shed and leaves a VERY large footprint.

With Ruby and Rails, my experience in learning curve was that the curve was low and short. Peaking the hill of learning these technologies was manageable, doable. Even without learning how to flex the technologies (I still don’t grok the metaclass), I have been able to overcome some serious design hurdles with the convenient flexibility of Ruby and the Rails framework.

Looking up, I notice ONE bolded phrase

CODER HAPPY

The reference… Ruby and Rails.

Hm..

I have an approved rails app to work on.

coder team alpha Out!

Apache/SCGI on Windows XP / 2003

I’m trying to configure a production-mode Win2003 server for rails apps.

I ran down the rabbit hole for all of the following configurations :

  • Cygwin/lighttpd SCGI/FastCGI: compiling errors on both my dev machine and vmware test.
  • InstantRails / SCGI : well, after figuring out how to run production-mode scgi_server as a windows service (details below), I still have trouble getting InstantRails to run as a “service” itself. This is not the fault of InstantRails, and Curt, you get KUDOS KUDOS KUDOS for the work in gettting InstantRails to work at all! (see below for some details on how to auotmate the scgi-as-a-service installation, when you get InstantRails running as a service itself (or at least the apache/mysql servers).
  • IIS / FastCGI : 404 error every time. With no log output, there’s nothign to see and nothing to do.. except look elsewhere for a solution!

Here’s the final solution :

Apache SCGI Configuration

Sexy is only skin deep in software

So I just watched the “5 minute video” by Iron Designer for .NET

Very sexy.  Very very sexy.

As an MSDN subscriber (thanks to my corporate sponsors employers) and MCP (SQL Designer test or something, I’ve forgotten), this is very enticing…

AND .NET has failed me in several situations where I was trying to do something “outside the box”.

How does Ruby on Rails compare to this ?

Well the 10 minute video is almost a religious experience to many.  AND Ruby and Rails DOES NOT fail us in situations where we wish to go “outside the box” in order to accomplish something.

That is all

Apache/SCGI on Windows XP / 2003

I ran down the rabbit hole for all of the following configurations :

  • Cygwin/lighttpd SCGI/FastCGI: compiling errors on both my dev machine and vmware test.
  • InstantRails / SCGI : well, after figuring out how to run production-mode scgi_server as a windows service (details below), I still have trouble getting InstantRails to run as a “service” itself. This is not the fault of InstantRails, and Curt, you get KUDOS KUDOS KUDOS for the work in gettting InstantRails to work at all! (see below for some details on how to auotmate the scgi-as-a-service installation, when you get InstantRails running as a service itself (or at least the apache/mysql servers).
  • IIS / FastCGI : 404 error every time. With no log output, there’s nothign to see and nothing to do.. except look elsewhere for a solution!

Here’s the final solution :

  1. Assuming your’e doing this on a virgin server : install ruby and rails and your rails app.. .test on webrick.
  2. Install Apache 2 (follow the directions, etc.)… test it for basic functionality “You were expecting your site but you got this page instead”.
  3. Go to Zed Shaw’s SCGI Rails Runner Howto site.
  4. Get the scgi gem and install it.
  5. Get the mod_scgi binary and copy to /modules (that link is assuming Apache 2… Zed has Apache 1 on the site as well.
  6. Configure /conf/httpd.conf according to the howto. This includes a LoadModule line and a configuration.
  7. Get srvany.exe kit from vbRad. Expand it to a simple location like C:\srvanykit.
  8. Run C:\srvanykit\instsrvw.exe. Follow the wizard. The PATH TO THE APPLICATION.EXE IS : C:\srvanykit\srvany.exe. THIS IS REQUIRED. You will configure the actual path to scgi_server in a minute.
  9. Run regedit. Find the key for your service at :
    HKLM/System/CurrentControlSet/Services/
  10. Add a new key : /Parameters
  11. Add a new string value : Parameters/Application.
    Value = (path-to-ruby) (path-to-scgi_server)
    Ie “C:\ruby\bin\ruby.exe C:\ruby\bin\scgi_server”
  12. Add a new string value : Parameters/AppDirectory.
    Value = (path-to-rails-app-root)
    Ie “D:\rails_apps\cookbook”
  13. Open Service control panel (Start -> Control Panel -> Adminstrative Tools -> Services). Find your service. Start it… should be running!
  14. Test the rails app: Go to http://localhost.
  15. If you have a routes issue it needs to be addressed now.

I’ll edit this post with updates as they are necessary.