Flex kisses Rails

by admin on December 28, 2008

Flex on Rails

Working with rails is a lot of fun, I’ll admit, but when you throw Flex into the Picture its like “The Real Side of The Force”. This is a small tutorial demonstrating how to get up and running with Flex and Rails!!

^This tutorial is for Windows users (yuck, can’t wait to get onto Linux), and is inspired by Peter Armstrongs Flexible Rails Book. Pre requisites for this tutorial are: Flex Builder/Rails 2.2.2/mysql (not needed but pre configured) and thats about it. If you are running an older version of Flex or Rails try and follow along, it should work out as its a basic demo without database interaction.

Configuring the Application:

  1. CREATE YOUR APPLICATION: This is very easy just create the app by using this command
  2. rails -d mysql flexonrails # tell Rails to use mysql instead of the default sqlite3 adapter

    *You should modify your command line prompt to start up with the directory your Rails Apps reside. My directory is D:/Rails Apps. All you have to do is click on the Command Line Shortcut and define the path in the “Start In” field.

    cmd_shortcut

    Other commands that might come in handy:
    D:\Rails Apps> mkdir flexonrails //create a directory named "flexonrails"
    D:\RailsApps> cd flexonrails //cd into the dir. you just created

    You can also use an IDE of your choice to create the application. I just switched over to netbeans.

  3. CHECK IF THE APP IS WORKING: Point your web browser at http://localhost:3000/ and you should get your normal Rails screen showing.

    Make sure that you create your database (even though we aren’t using it in this small demo.) You should get used to doing that.

    Your "flexonrails" App @ http://localhost:3000/

  4. CREATE THE FLEX PROJECT: I will be using Flex Builder 3 here, but you can easily use the FLEX SDK. Before you go ahead and create the project make sure to create these folders within your application direcotry.
    D:\Rails Apps\flexonrails> mkdir app/flex //creates the flex dir within the app dir.
    ….
    D:\Rails Apps/flexonrails> mkdir public/bin //creates the bin dir withing the public dir.


    Create a Flex Project


    Change the output folder to public\bin

    ….
    Final Flex Project Configuration

  5. CREATE THE CONTROLLER IN RAILS: Create the controller in rails by using the normal:
    ruby script/generate controller {your controller name}

    (OR copy and paste the following to Controllers/hello_controller.rb)

    class HelloController < ApplicationController
      def hello
        render :text => "hello world!"
      end
    end
    
  6. CREATE THE MXML: You will have to create the mxml which is pretty straightforward here. First rename your flexonrails.mxml to Flexonrails.mxml to avoid any naming conventions. Then copy this code over:
    
    
    
    
    
    
    
  7. BUILD THE PROJECT AND POINT: All you have to do now is build the project (In Flex Project>Build Project and make sure Build Automatically is unchecked).

    Next point your browser to:
    http://localhost:3000/bin/FlexonRails.html

That should do it for you. In case it doesn’t work make sure that you:
(1) Saved your files.
(2) Configured Rails properly.
(3) Configured your Flex Builder Project Properly.
(4) Created the public/bin AND app/flex sub directories.

This should give some good insight on how to setup a Rails and Flex Project. Sure it might take some time to start creating bigger apps, and apps that connect to a database, but this is sure a good start.

{ 2 comments… read them below or add one }

FreedomNo Gravatar December 29, 2008 at 5:54 am

Possibilities are just endless here…..

Reply

AsimNo Gravatar January 11, 2009 at 3:02 am

Kool@:) interesting

Reply

Leave a Comment