Sunday, October 31, 2010

Rails Application variable

It almost seemed that there was no easy way out of putting application scope variables in the database.
But there is a way out:
    if Thread.main[:uuid] == nil
      Thread.main[:uuid]=0
    end
    uid = Thread.main[:uuid] += 1


This code accesses the mail thread of the rails process and puts a variable on it. (the thread is an object and can have key => value sets)
And since rails has only one main thread... its shared with all the threads underneath.

Good Luck

Friday, October 29, 2010

Multilingual Support for Flex

Some Cowboy coding techniques for supporting multilingual flex interfaces:
Instead of the usual form (from an Adobe development center post):
...text="{resourceManager.getString('resources', 'POSTDISPLAY_POST_TITLE')}"...
My label looks like:
...text="{gS['POSTDISPLAY_POST_TITLE']}"...
Which is so much shorter and nicer to read when you are coding.

The gS is actually a static object (i.e. hash map) that I load with all the key:value pairs of the language.
Once you declare gS as [Bindable] you can replace the object at runtime with other languages, resulting with the replacement of all the strings in the application.

Note: the compiler issues a warning that since you are using square brackets, the GUI object will not be able to detect changes in the data source. Well, it does.

Independent on Sundays




Thursday, October 28, 2010

"localhost" Server isn't working? Blame Skype!

Skype is the DevilIt took me a while to reach this grim conclusion, The Skype client blocks quite allot of communication ports on the machine its running on. Apache Tomcat, WAMP and RoR are effected (as far as i can tell).

 
Solution:
Kill the Skype process.

Good Luck.

Wednesday, October 27, 2010

Exporting from SQLServer to SQL insert script

The problem:
Export data from an MS SQL server to an SQL script of insert statements

It appears that there is no built in option for performing such a simple a task. After all, SQL is the common protocol for SQL based databases.

What i did manage to find is a script (stored procedure) for SQLServer 2000 and SQLServer 2005
The original post and instructions are available here.

Good luck

Sunday, October 24, 2010

AAdmin - Flex on Rails Agile Admin Application

The AAdmin is a little project I'm developing on the side, for Valueshine which in essence is a fast Administration Application based on a Ruby on Rails back-end and a Flex Web front-end.

I love fast development mainly because I'm a lazy son of a batch file and for some reason, I feel that Ruby and Rails was made just for people like me.

Having a server side application that 70% of its tasks sum up to persistence functionality just screamed scaffolding to me. the only obvious difference is that for the sake of using a flex client, i would have to skip over the default view machinery, that are generated by the rails scaffold.

Pre Programming:
I've created the alternative controller template so scaffolding command would generate an XML based web service.
to match that I've written an ActionScript client side that talks CRUD on the one side and hands out a set of a-sync methods on the other side.

The application, is based on the two elements described above, let me have a RoR restful web services that would accommodate a rich client.

The server:
I have employed a standard scaffold script generation with a tweak to the controller template. this change bypasses the standard view that is created by Rails to relay on pure XML rendering.
there is one extra controller that is utilized for configuration data purpose. I use it for authentication, and to extract the entities structure xml file.

The Client:
This part is where the quick admin app comes to play. the AAdmin client enables all CRUD functionality on a list of entities, predefined in an entity xml.
the client logs in, extracts the entity xml file, and presents the table structure and functionality according to the definitional in the file.

Screen shoots:
AAdmin Login Screen.

The CRUD Data View

The Create and Edit screen















Resources:

Wednesday, October 20, 2010

Flex for Rails Scaffolding (cont) - the controller template

I've made a little improvement  to my development process, in such a way that the scaffolding i do for creating the web services I later use for my flex client are generated in their final form without the need to adjust them.
What i did was make some changes to the controller scaffold template.
The controller.rb template file is located at: [Ruby Home]\lib\ruby\gems\1.8\gems\rails-2.3.4\lib\rails_generator\generators\components\scaffold\templates

Backup the original (or pick it up from here).
Download the modified template


The Template should end up looking like:

class <%= controller_class_name %>Controller < ApplicationController
  # GET /<%= table_name %>
  # GET /<%= table_name %>.xml
  def index
    @<%= file_name %> = <%= class_name %>.all
   render :xml => @<%= file_name %>
  end

  # GET /<%= table_name %>/1
  # GET /<%= table_name %>/1.xml
  def show
    @<%= file_name %> = <%= class_name %>.find(params[:id])
    render :xml => @<%= file_name %>
  end

  # GET /<%= table_name %>/new
  # GET /<%= table_name %>/new.xml
  def new
   @<%= file_name %> = <%= class_name %>.new
   render :xml => @<%= file_name %>
  end

  # GET /<%= table_name %>/1/edit
  def edit
    @<%= file_name %> = <%= class_name %>.find(params[:id])
   render :xml => @<%= file_name %>
  end

  # POST /<%= table_name %>
  # POST /<%= table_name %>.xml
  def create
    @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
    if @<%= file_name %>.save
      render :xml => {:notice => '<%= class_name %> was successfully created.'}
    else
      render :xml => {:notice => @<%= file_name %>.errors}
    end
  end

  # PUT /<%= table_name %>/1
  # PUT /<%= table_name %>/1.xml
  def update
    @<%= file_name %> = <%= class_name %>.find(params[:id])

    if <%= file_name %>.update_attributes(params[:<%= file_name %>])
      render :xml => {:notice => '<%= class_name %> was successfully updated.'}
    else
      render :xml => {:notice => @<%= file_name %>.errors}
    end
  end

  # DELETE /<%= table_name %>/1
  # DELETE /<%= table_name %>/1.xml
  def destroy
    @<%= file_name %> = <%= class_name %>.find(params[:id])
    @<%= file_name %>.destroy

    render :xml => {:notice => '<%= class_name %> was successfully deleted.'}
  end
end