WebSnapshot and RailsLogVisualizer ported to AIR 1.0 6

Posted by Daniel Wanja Tue, 26 Feb 2008 06:28:03 GMT

I ported the WebSnapshot and RailsLogVisualizer application to AIR 1.0

20080225_WebSnapshot.jpg

20080225_RailsLogVisualizer.jpg

Enjoy, Daniel

Something in the AIR? 3

Posted by Daniel Wanja Sat, 23 Feb 2008 03:30:45 GMT

360Flex in Atlanta starts this monday. I was at the first 360Flex conference last year and it was a blast. I will miss going to that one. Also it seems that many Flex User Groups meetings around the world (Atlanta, Bangalore, London, Denver, Amsterdam) will held on this monday. When so many planets will align perfectly something special is bound to occur.

So more specifically from the Special Meeting invites:

  • Exclusive user group video presentation by Adobe Chief Software Architect, Kevin Lynch
  • In-person presentation from Adobe Platform Evangelist, Kevin Hoyt
  • And…important product news!

That can mean only one thing. It’s gonna be soon time to recompile all my apps ;-)

Update 1: the Denver meeting is not on the 25th but on March 11th. Update 2: Ted Patrick announces yesterday that the Flex 3.0 and AIR 1.0 releases is days away. Update 3: Flex 3.0 and AIR 1.0 are out. Go try out FlexBuilder if you haven’t yet, it’s the easiest way to get started.

Heroku.com - An impressive online Ruby on Rails Platform. 5

Posted by Daniel Wanja Thu, 21 Feb 2008 05:12:19 GMT

You’ve have to try it to believe it. It’s awesome that you can create a Rails application and deploy it all online. Nothing to install, it’s all there. I think it’s an awesome addition to the Rails world. It may not replace your development environment, but for deployment it’s pretty flexible and is based on Amazon EC2.

From their website the feature description is as follows:

  • Instant Deployment
  • Create and Edit Online
  • Integrated Stack
  • Elastic Performance
  • Share and Collaborate
  • Import & Export
  • Full Ruby Environment
  • Gems & Plugins
  • Rails Console
  • Generate Code
  • Painless Migrations
  • Rake Console

But you gotta see this to believe it. I made a quick screencast, so if you are not scared of a thick (swiss) french accent, have a look: (click image to open screencast in separate browser):

20080220_HerokuSmall.jpg

I can foresee, at least hope, that they will quickly add support for subversion and for Capistrano based deployment, hence becoming the ultimate deployment platform for Rails in addition to the powerful and flexible environment they already provide.

I signed up and received my invite three days later. If you can’t wait send me an email daniel[at]onrails.org, and I sign you up, that will allow to skip the wait.

Enjoy, Daniel.

Dealing with HTTP errors in a Flex with Rails application. 9

Posted by Daniel Wanja Wed, 20 Feb 2008 15:56:23 GMT

The Flash Player is restricted in the way it deals with HTTP errors. This is mainly due to provide cross browser consistency and I believe is due to the restrictions the browser imposes on the Flash Player plugin. In fact when your Flex application performs HTTP requests using the HTTPService class, the request is passed by the Flash Player to the browser and in case of an Rails error (500, 404, ...) the response is somehow crippled on the way back.

Problem

So let’s consider that the Flex application requests to update a Person but the validation fails. In the update method of our Rails controller the HTTP Status is set to :unprocessable_entity. This corresponds the HTTP error code 422.
  # PUT /people/1
  # PUT /people/1.xml
  def update
    @person = Person.find(params[:id])

    respond_to do |format|
      if @person.update_attributes(params[:person])
        flash[:notice] = 'Person was successfully updated.'
        format.html { redirect_to(@person) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @person.errors, :status => :unprocessable_entity }
      end
    end
  end

Now in our Flex application by default we cannot identify that the error 422 occured, more annoyingly we cannot retrieve the Rails error messages. All we get back is the following:

[FaultEvent fault=[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://localhost:3000/people/8.xml?_method=put"]. URL: http://localhost:3000/people/8.xml?_method=put"] messageId="65EBBA92-5911-68D2-1710-18A687C28455" type="fault" bubbles=false cancelable=true eventPhase=2]

Solution

I haven’t found a way to have the status code and error message appear in the Flex application without having to change the Rails application. But fortunately, I was able to deal with that by using an after_filter at the application controller level, hence having only one place in the application to take care of all controllers and requests. The trick is to “hide” the HTTP Status error code in Rails and as the Flex application deals with XML responses, simply check in Flex if the response starts with <errors>. This can then also be dealt with in the Flex application in one place of the application. In a Cairngorm application I had the Delegate transform these “errors” responses to Faults.

Here is an example of the change to the Rails ApplicationController.

class ApplicationController < ActionController::Base

  after_filter :flex_error_handling

  def flex_error_handling
    response.headers['Status'] = interpret_status(200) if response.headers['Status'] == interpret_status(422)
  end

  def rescue_action_in_public(exception)
    render_exception(exception)
  end
  def rescue_action_locally(exception)
    render_exception(exception)
  end

  rescue_from ActiveRecord::RecordNotFound, :with => :render_exception
  def render_exception(exception)
    render :text => "<errors><error>#{exception}</error></errors>", :status => 200 
  end

end

Flexible Rails: A book on using Flex with Rails. 2

Posted by Daniel Wanja Wed, 20 Feb 2008 15:31:08 GMT

As many of you know I really enjoy using Flex with Rails. So I finally picked-up a copy of FlexibleRails which is written by Peter Armstrong and started browsing through it last week-end. For anyone out there trying to enrich their application with some Flex or even writing the whole UI in Flex, check out this book as it’s a good starting point and Peter addresses many of the aspects that you will be faced with. Peter goes through several iterations of creating an application and introduces the reader to using Flex against a RESTful Rails application, he refactors the application to Cairngorm, uses AMF. So congratulations Peter of getting this done!

Does a good idea make a good business?...One year later! 10

Posted by Daniel Wanja Thu, 07 Feb 2008 05:00:12 GMT

A year ago we started a new venture to create small internet “service” business. We had an idea, and started implementing it Monday nights. I would like to use this blog post to reflect on where we are at. The short story is that a year after we still haven’t released a version and that feels a little frustrating. A year ago I asked on this blog if a good idea makes a good business? I was really trying to think about which of the different ideas we had I wanted to follow. Several people contacted me on the blog and offline, and I liked Pascal’s comment on the question mentioning that it boils down to execution. Reflecting on this, I believe we executed well, we persevered, we made huge progress, we solved many technical challenges, the application starts to look good, starts to work pretty well, is useful, but is not done yet. The main reasons is that we need to build a massive server side infrastructure to support this service. This isn’t as bad as it sounds as today with EC2, S3, and other hosting providers you can create some pretty scalable solutions in a pretty cost effective way, but we need to nail this down before starting to open the service to the public. Now you may wonder why we don’t just doit! This is the reasons why I am writing this post. I’ll be slowing down my “outside normal work” activities over the next several month to focus on our soon to be released child #3. Lee also just had child #1, and it will certainly take him some time to adjust to his new environment and schedule. It wouldn’t be fair to let Sol carry the development on by himself during that time and Lomax, the designer, really needs the developers to get the backend going before adding his magic design touch to the user interface. So I believe focus, patience and perseverance is also required to make a good business. It’s hard to explain in words, but the service we are developing will be useful for many internet users in it’s first iteration, and we already envision the next version that will allow to target online companies and will provide them with a unique service which hopefully will be very profitable for us. So I hope we will pickup the development in a couple of month and just be able to get it out the door. This will then only be the beginning…

Have fun! Daniel.

RailsConf registration opens today. Be ready! 2

Posted by Daniel Wanja Tue, 29 Jan 2008 14:10:53 GMT

May 29-June 1, 2008 in Portland, Oregon,

UPDATE: registration is now open.

UPDATE2: I’ll be presenting with Tony a 3 hour tutorial on Powering AIR Applications with Rails. See you all there!

I Always Knew IE Was Shifty 6

Posted by Solomon White Sun, 27 Jan 2008 05:17:00 GMT

While working on a Rails project, I stumbled upon a (probably) obscure positioning bug in IE, triggered by the ubiquitous “Yellow Fade Technique”, of all things. The symptom, as reported by the user, was that form elements on a page were “jumping around” when items were added to the cart. I’ve distilled the issue down to what I believe is the smallest reproduction of the issue, which I present to you now, in glorious validated HTML 4.01 strict:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head>
    <title>IE Shifting Bug</title>
    <style type="text/css">
      div { position: relative;}
    </style>
  </head>
  <body>
    <div style="float:right; width:49%">
      <div style="display:none;">
        some hidden content
      </div>
      <div id="container">
        <label>Overlap Me:</label>
        <input type="text" value="<< this should shift">
        <input type="submit" value="&laquo;this too">
      </div>
    </div>

    <!-- trigger to illustrate the bug: -->

    <p>
      <input type="button" value="apply background color"
        onclick="document.getElementById('container').style.backgroundColor = 'yellow'">
    </p>

  </body>
</html>

If you view this page in IE (I’m using version 7), when you apply the background color to the container div, the two form elements jump to the left, overlapping the label element. Interestingly enough, this seems to require the convergence of many things, including the floated outer div, the hidden content above, the relative position on all the divs, etc. If you remove any of them from the equation, things work as expected. In an even more bizarre twist, the length of the label seems to come into play as well—if you add even one more character to the label text, things return to “normal”.

In the extremely unlikely event that anyone else has run across this issue, hopefully I can save you a couple of hours of frustration. I worked around the issue by overriding the position of the “container” div (to “static”), although given the fragility of the trigger, any number of small changes should work as well.

BenchmarkForRails Viewer Ruby on Rails plugin (with Juggernaut's server push technology). 8

Posted by Daniel Wanja Sun, 06 Jan 2008 05:08:17 GMT

Release early, release often they say. I don’t know if I’m going to release often but this is very early for this project. In fact yesterday I was testing the excellent Juggernaut plugin for Ruby on Rails, a “server push technology”, created by Alex McCaw and at the same time I was trying out the BenchmarkForRails plugin. The BenchmarkForRails plugin adds some detailed log information about the time breakdown for a request in the following format:
- [0.0954] GET /categories -----------------------
   0.0791 action
   0.0098 development mode
   0.0026 finders
   0.0003 session
   0.0001 rendering
   0.0001 filters
------------------------------ BenchmarkForRails -

Of course I had to look how it was implemented and it didn’t take me long, (once I overcame a self inflicted issue for which Alex McCaw helped me out. Thanks man!), to try to combine the BenchmarkForRails, Juggernaut, and Adobe’s Flex to create a little Benchmark Viewer that looks as follows:

http://localhost:3000/benchmark/BenchmarkForRails.html 20080105_bencmarkforrailsviewer.jpg

Note: that’s the only view currently supported. The ‘last’, ‘last 5’, ‘last’, ‘last 5 (same), selection will provide different views of your requests but this functionality isn’t yet coded. Also filtering by controller and action would be nice.

Like I said this is very early but combining Benchmarking with server push technology offers quite some potential, but let’s keep it simple for now…

Well, the installation is not as simple as it could be for the moment I provided some steps here after. To run the application simply start the Juggernaut push server, start you server as usual, and you will see the time details of each request in the viewer. The time is color coded to indicate wether the time was slower (red), faster (green), or same (white) than the previous request of the same type (controller, action, method).

Note for the installation you must use the http://juggernaut.rubyforge.org/svn/branches/juggernaut_1.0/ version. This is a more recent version than trunk and Alex will put it to trunk soon. Also the Flex client uses the default port 5001 to talk to the push server. If that’s an issue for you then you are out of luck. Not for long, as this is the next thing I will change in the Flex application.

INSTALLATION

You need the following plugins: benchmarkforrails, juggernaut, and benchmarkforrails_viewer

a) benchmarkforrails
$ svn export http://benchmarkforrails.googlecode.com/svn/trunk vendor/plugins/benchmarkforrails
b) juggernaut
$ svn export http://juggernaut.rubyforge.org/svn/branches/juggernaut_1.0/ vendor/plugins/juggernaut
$ rake juggernaut:reinstall  
This creates the conf/juggernaut.yml and conf/juggernaut_hosts.yml file. Note juggernaut has detailed installation instruction. But in short you need the json and the eventmachine gems. c) benchmarkforrails_viewer
$ svn export http://onrails.googlecode.com/svn/trunk/plugins/benchmarkforrails_viewer vendor/plugins/benchmarkforrails_viewer
$ rake benchmarkforrails_viewer:reinstall
The later copies the UI files into the public/benchmark folder.

RUNNING THE VIEWER

1) Start the juggernaut push_server.
    cd vendor/plugins/juggernaut/media/
    # The first time you need to generate a config file using:
     ruby juggernaut -g
    # Start the push_server
     ruby juggernaut 

2) In a different terminal start your rails server, ./script/server

3) Start the BenchmarkForRails Viewer: http://localhost:3000/benchmark/BenchmarkForRails.html Note you need the Flash Player 9 installed.

4) Run your application (only in development) as usual and see the request benchmarks in the viewer.

The next functionality I would like to add is to make the port configurable in the Flex application, to add different views to view the requests. I shall also contact the guys that developed the BenchmarkForRails plugin to see if they could add a standard ways of plugging different reporting engines. But more importantly I would like to get your feedback. Let me know if this worked for you and if what else you would expect from such a viewer. I am sure I will hear from you if I forgot some details….Yea, like I think this only works for Rails 2.

Enjoy! Daniel

What's in for 2008 3

Posted by Daniel Wanja Thu, 03 Jan 2008 04:38:08 GMT

Thank you and Happy New Year to all the readers. 2007 was impressive over 101,740 page views on this blog. I am always amazed that people come read what is on this blog, as it’s often written very late at night or on the spur of the moment. Thank you again. As usual there are many objectives I didn’t reach in 2007, but the ride was worthwhile. So without commitments :-) here are a couples of things I like to work on (and blog about) in 2008:

  • MySpyder.net with Lee, Sol, and Lomax we started a side project early last year. It’s looking really promising but we recently went back to the drawing board to be able to scale massively from a server side point of view. Many blog entries originate from this project. I hope that we get this project back on track and be able to show something cool in a couple of month.
  • Flex On Rails – the book. One must be nuts to write a book, so I though why not give it a try. It’s definitively a long process but I have some partners in crime that seem even crazier than me…so there is hope that we get something cool out the doors.
  • Flex Dynamic Scaffolding for Rails. This is more a thought, but I would love to create a small Scaffolding framework showing off the potential of Flex.
  • RailsLogVisualizer plugin. A nice plugin to shows real time usage of a Rails application.
  • Amazon Web Services. Build a nice application that makes uses of S3, EC2, SimpleDB and DevPay. I should be able to find a problem to my solution.

Have a great year everybody! Daniel

Older posts: 1 ... 4 5 6 7 8 ... 20