Rails – where is the missing stuff?

December 3rd, 2009

ROR (Ruby on Rails) is advertised as a data-centric development framework.  I did what I considered Data-dev back in the 1980′s using 4GLs:

  • you created a schema for your data (it was a bit more involved since data fields were ‘typed’)
  • you created views, reports, etc. for your data (just drop your fields onto screen forms, apply desired formatting/presentation switches, add any needed logic, etc.)
  • you connected everything via menus or ‘links’ within screens
  • there were ‘hooks’ for everything (so you could connect data/processes/whatever/call external programs)
  • everything was ‘menu driven’ – and FAST (the self-contained model is simply simpler and performance simply reflects your hardware since there were no network services involved)
  • note that for most folks, with the exception of apps running under *NIX this was a PC (stand alone) world…

With recent software development ‘frameworks’ that I have seen some basic items seem to be missing – my comments are based on an aged view (been there, done that – or something close…; this is still cool/interesting but wish it were a bit more comprehensive…)  Of course the really nice aspect of Open Source is that you can customize/alter everything.  :)   WARNING – newbie posting about new stuff so I will really be surprised if I don’t miss, well, quite a bit – and I certainly welcome constructive tips like, “Have you tried the XYZ Rails option – it already does everything you mention -  already – really…”

What’s (maybe) Missing Example # 1

Rails provides all this wonderful ‘get setup’ but NO menu generate for the entire project?  It would be relatively simple to generate a list of Potential menu Links based on the view folder contents.  Yes, I know that you can ‘install yet-another-app-for-that’ - my point is that this is BASIC and should be part of the framework, i.e. ‘rails new_project‘ should include a basic-get-started-menu, IMO – you have a ton of other goodies and if you don’t want/need it then trash it…

What’s (maybe) Missing Example #2

In the MVC (model-view-controller) framework world you get default views – why not include just a bit more along the standard presentation front?  i.e.  With CSS it is relatively easy to include a complete presentation framework for your web coding framework (FFF, F4F – frameworks for frameworks!) In this case I suggest considering something like http://960.gs/ – watch the Netnutts 960 video and see why a FFF/F4F might be a good approach.  While you are at it go ahead and create both Mobile and Print CSS views.  You do this once with a solid CSS foundation and just include it as part of your default when setting up new projects.  Hmm, and then there is data validation - how can I quickly/easily/at-the-time-of-schema-creation include these data attributes/aspects?  [Yes, I know that I can change my 'model' to include validation - but I want it all at once!]

A simple ROR Address Book App

An example, very simple app might be an address book.  Creating a working application using a 1980′s 4GL could be done in less than 30 minutes – and include some secondary tables that provided lookups for ZIP codes and/or country codes (i.e. 30 minutes to create: reports for all tables, CRUD views for all tables, exports for all tables, linked data for appropriate tables).  If creating such an app today the data ‘fields’ might include:

  • name (text)
  • address line 1 (text)
  • address line 2 (text)
  • city (text)
  • state code (text)
  • country code(text)
  • zip (numeric)
  • home phone (formatted numeric)
  • work phone (formatted numeric)
  • email (text)
  • web site (personal) (text)
  • web site (professional) (text)
  • web site (blog) (text)

Taking the above and  using ROR scaffolding we might get started by:

script/generate scaffold contacts name:string address_one:string address_two:string city:string country:string zip:integer home_phone:string work_phone:string email:string web_personal:string web_professiona:string web_blog:string

Note that while a command-line-guy I do enjoy using Aptana  RadRails (a very nice multi-language IDE – in this instance I am using Sqlite3 so no server-wide database setup is needed) since it provides simple window/menu options for completing these typical Rails tasks. If using the command line your steps might be:

  1. cd /your/path/to/projects/folder (change to your work folder)
  2. rails contacts (auto-generate the framework components for your project)
  3. cd contacts
  4. script/generate scaffold contacts name:string address_one:string address_two:string city:string country:string zip:integer home_phone:string work_phone:string email:string web_personal:string web_professiona:string web_blog:string (create your data fields with designated data-types)

Note that there is some debate about using or not using Rails scaffolding (as a ROR newbie I don’t have an opinion but my preference is going to be for a DRY solution for anything dealing with data – let me define it in ONE place and everything [or as much as possible] else should simply be done auto-magically…)

This seems like it is WAY faster than the 4GL I referred to…

I’m already able to use the data interface and the most difficult part (well, so far anyway) is listing my desired data fields (and remembering to do a spell-check.)  :)   If all goes well we have a working web interface to the above data at our default URL of http://0.0.0.0:3006/contacts (your PORT number will vary – and RadRAils provides auto-incremented port numbers as you create projects – in my case this is project #6.)

Ok, the bad news - while very quick & easy to create and certainly functional/useable, the app has presentation woes:

  • I made some typos when creating it
  • I left out the ‘state’ field
  • the default (un-formatted layout) of the entry form requires me to scroll down to complete the form
  • there is no data validation for any of the data
  • the default list-view has things all-scrunched-up (unless you have a 20″+ monitor…)

So now, the work begins

The steps missed/not-taken for defining both validation and presentation properties for my data fields will take their toll.  I now need to either modify existing files (which were auto-generated for me by the Rails scaffold tool) or I need to create new files to manage some of my concerns.  I decide to trash what I have try a new scaffold line with my missing fields added and spelling corrected:

  • rake db:drop (erase the database – try leaving this step out – or erase the ~/db/migrate/*rb migration files)
  • script/generate scaffold contacts first_name:string last_name:string address_one:string address_two:string city:string state:string country:string zip:integer home_phone:string work_phone:string email:string web_personal:string web_professional:string web_blog:string
  • rake db:migrate
  • run the app (refresh your browser)

Ok, that’s better; easy to fix simple problem or add new fields.  Note that you could also edit your schema.rb file directly and then migrate (try it.)

At this point I decide to create a ‘site controller’ – something that I can use to connect things to or expand from.

  • I run: script/generate controller site home reports help about (I will use this for navigation)

Now I’m going to take a leap/jump/plunge/diversion/advanced-move by adding a debug option to my pages by including some Javascript magic (which of course, I have borrowed from elsewhere…)  I’m also going to create two default, site/project-wide files (well, only two for now) and edit my main app html file:

  • create:  /apps/layouts/shared/_debug.html.erb and I add the code below
<% if ENV["RAILS_ENV"] == "development" %>
<div id="debug">
 <h4>DEBUG Info Below</h3>
 <!-- some Javascript -->
 <a href="#" onclick="Element.toggle('params_debug_info'); return false"> params </a>
 |
 <a href="#" onclick="Element.toggle('session_debug_info'); return false"> session</a>
 |
 <a href="#" onclick="Element.toggle('env_debug_info'); return false"> env</a>
 |
 <a href="#" onclick="Element.toggle('request_debug_info'); return false"> request </a>

 <!-- some formatted, hidden data -->
 <fieldset id="params_debug_info" style="display:none">
 <legend>params</legend>
 <%= debug(params) %>
 </fieldset>

 <fieldset id="session_debug_info" style="display:none">    
 <legend>session</legend>
 <%= debug(session) %>
 </fieldset>

 <fieldset id="env_debug_info" style="display:none">    
 <legend>env</legend>
 <%= debug(request.env) %>
 </fieldset>

 <fieldset id="request_debug_info" style="display:none">    
 <legend>request</legend>
 <%= debug(request) %>
 </fieldset>
</div>
<% end %>
  • create:  /apps/layouts/shared/_navigation.html.erb and add the code below:
<div id="nav">
    <!-- ### added a navigation 'helper' -->
    <%= def_nav_link "Contacts Home", "contacts" %> |
    <%= def_nav_link "Reports", "reports, "index"%> |

    <%= def_nav_link "Help", "site", "help" %> |
    <%= def_nav_link "About", "site", "about" %> |
    <span style="float: right">
        <%= def_nav_link "Register", "user", "register" %> |
    </span>           
</div> <!-- nav -->
  • edit /apps/views/layouts/contacts.html.erb and modify the <head> section to include a Javascript line.
<%= javascript_include_tag :defaults %>

Now refresh your browser – check out the bottom of the page.  We have essentially added a ‘debug footer’ that only shows us what we want to see when we want to see it – in addition, this only shows up when ‘in development’…

Wait, Wait, Wait – what about quick, simple, direct create the ready to use app????

Sorry, I’ll pick this up on a future post, and yes, for a newbie this will take a bit longer than my 30 minute to finished product 4GL days…

Suggested Rails projects sequence – Synopsis – Reverse the process a bit:

  1. start with a ‘site’ controller
  2. add common, shared resources (debug & nav & CSS)
  3. then add ‘content’ goodies (contacts)

As always, your mileage should vary.   :)

<% if ENV["RAILS_ENV"] == “development” %>
<div id=”debug”>
<h4>DEBUG Info Below</h3>
<!– some Javascript –>
<a href=”#” onclick=”Element.toggle(‘params_debug_info’); return false”> params </a>
|
<a href=”#” onclick=”Element.toggle(‘session_debug_info’); return false”> session</a>
|
<a href=”#” onclick=”Element.toggle(‘env_debug_info’); return false”> env</a>
|
<a href=”#” onclick=”Element.toggle(‘request_debug_info’); return false”> request </a>

<!– some formatted, hidden data –>
<fieldset id=”params_debug_info” class=”debug_info” style=”display:none”>
<legend>params</legend>
<%= debug(params) %>
</fieldset>

<fieldset id=”session_debug_info” class=”debug_info” style=”display:none”>
<legend>session</legend>
<%= debug(session) %>
</fieldset>

<fieldset id=”env_debug_info” class=”debug_info” style=”display:none”>
<legend>env</legend>
<%= debug(request.env) %>
</fieldset>

<fieldset id=”request_debug_info” class=”debug_info” style=”display:none”>
<legend>request</legend>
<%= debug(request) %>
</fieldset>
</div>
<% end %>

Share and Enjoy:
  • LinkedIn
  • Digg
  • del.icio.us
  • Google Bookmarks
  • Technorati
  • Live
  • Slashdot
  • Sphinn
  • Mixx
  • Yahoo! Buzz
  • StumbleUpon
  • Facebook
  • MSN Reporter
  • Reddit
  • RSS
  • Add to favorites
  • FriendFeed

Related posts:

  1. Search Engines – what’s missing? We have some great generic search tools and a few...
  2. VirtualBox 2.1.2 – missing tools? I expect things to improve when I update/upgrade software –...
  3. Hobo – fasssssssssstttt Rails 3 Apps/Site? I started out with a Rails 3.1 install and then...
  4. What’s missing: solution engine vs search engine Do we need a new option from the search engines...
  5. Rails – simple problems NOTE – I’m simply writing about what I find as...

Comments are closed.
________________________________________________
YOUR GeoIP Data | Ip: 38.107.179.224
Continent: NA | Country Code: US | Country Name: United States
Region: CA | State/Region Name: California | City: Glendora
(US only) Area Code: 626 | Postal code/Zip:
Latitude: 34.132099 | Longitude: -117.851097
Note - if using a mobile device your physical location may NOT be accurate...
________________________________________________

Georgia-USA.Com - Web Hosting for Business
____________________________________