Archive for the ‘rubyonrails’ Category

Ruby on Rails with CSS Frameworks

Monday, June 18th, 2007

I’m no designer. This webpage is perhaps proof of that. However, taking that into account, I have to create webpages with at least some design to them. Notably business apps and admin control areas.

Now in this day and age we all should be using CSS to control layout and typeface definitions, none of that inline stuff too. This however can be a rather tedious and painful business for somebody such as myself.

The problem with this perhaps is that the only help rails give you in the term of CSS is a helper method that creates the html head CSS import and a standard and slightly ugly scaffold.css document. So my overriding issue is that whilst rolling around in Ruby joy, my CSS is gets messy. It ends up in an near unmaintainable heap, laden with IE hacks and unorganised in nature. Grr horrid.

What I really need to do is make some code that I can reuse over and over again.

A CSS FRAMEWORK if you will, which can be extended and reused for each project.

So I’m exploring this right now. There are a few lying around the net, including one by the behemoth that is Yahoo!

Content with style CSS framework - http://www.contentwithstyle.co.uk/Articles/17/
Yahoo! CSS Grids - http://developer.yahoo.com/yui/grids/

Now if Rails could help with its scaffold function, producing something of more than scaffold.css, that would be swell.

Ruby on Rails with Google Gears

Thursday, May 31st, 2007

Prelude
This post is just my head throwing ideas about. Non of which are fully formed, nor fully investigated.

Intro
Today Google labs spitted out an early “plugin” for Internet explorer and firefox to make websites viewable and interactive offline. This isn’t entirely new as Apollo offers something similar. However, this is interesting considering Google is one of the kings of webapps. With Gmail, Google Calender and Google Docs all obviously the target for this technology I doubt that it would fail spectacularly.

Very brief and rubbish Gears overview
First off, there are two main components to Gears. The webserver and the database. The webserver is pretty simple to get our heads round, it essentailly caches pages that us as developers tell it to. For me the most interesting parts is the database.

The Gears Plugin that the user installs includes a fully relational SQLite database. As developers we can interacted with it by passing SQL commands via javascript. Yes thats right… we interact with it by using javascript code such as

var rs = db.execute('select * from Demo order by Timestamp desc');

The benifits of this are pretty interesting. For example webservers technically don’t have to store information at their end, ever, just relying upon the users own store.

I feel however the most use of such an app would be for something like gmail, where when you are offline you write and send an email with gears facilitating the actual sending of the email when the internet becomes available.

So how would Rails fit into all of this?
I love writing webapps in rails. Its quick, easy and Ruby is lovely to write. So could developing a Rails app with gears functionality be a possibility without having to drop into insane javascripty-SQL-type goo every time?

The answer in my opinion is yes, but it won’t be easy.

Here are the major barriers in the way to making a my ideal acts_as_gears type plugin.

  1. The plugin should be able to convert Ruby into javascript for offline controllers and model interactions. A massive undertaking (possibly recreating active record in javascript.. shudder).
  2. Creating the user’s local database and linking each column with the live database columns would be essential if we wanted to do any sort of syncing.
  3. The automatic creation of database syncing methods in javascript and ruby.
  4. Creating a seamlessness of data origin in views. For example, a table of information should be able to be printed out on one page irrespective if data came via the live or local database.
  5. The views should only have to be writen once, with of cause different javascript payloads.
  6. Loading and unloading of data needs and state management.

Anyway that’s what’s on my mind right now, a half baked whirlpool of rails, javascript and gears.

Reading
Google gears
Adobe Apollo
Firefox offline info

Multi threaded Ruby on Rails actions?

Thursday, March 22nd, 2007

I’m currently making an app that will spit out pdf reports all over the shop. These reports will get kinda big, doing loads of database calls and rendering images. As such it could take 15 seconds or more to render. Making the reports on the fly therefore could be a horrid user experience with unexpected waits and halts (and a nightmare for a server admin).

So my first attempt was batch the process, as the majority of the data that the pdfs render only changes about once a day. The batch process would go through our database and render all the reports and dump them out to file. User access then would be instantaneous. Wonderful!

The problem is that some bits of data can change at any time. For example these reports display a contact name and email address at the top. So if that changed, the pdf wouldn’t reflect this. Not very professional.

To combat this I added a spooling table, where if some data changed a request was added to a table. A script would then run every minute that would process the pending requests.

This is a slightly dumb approach, I know. What I need is two threads. So when the user updates the contact information, one thread would render the html page as usual and the other to render the pdf. The benefit being that the user doesn’t have to wait for the pdf thread to complete.

Ruby can deal with threads but finding information about doing a task like this is tough, let alone with Rails. Any help out there?

Readings
Rails wiki on threads
Ruby Reliable Messaging Gem
Reliable Messaging Rails example

Ruby on Rails is too slow on dreamhost

Sunday, March 11th, 2007

At work I develop Ruby on Rails applications on my wonderful little Ubuntu servers using apache2, fcgid and mysql5. They work a treat, fast responsive and is basically an easy stage to bounce off new apps. So when I was thinking about my own apps I knew I wouldn’t be able to get the same spec machine and redundancy for what I can afford, but I thought I would give dreamhost a try, I should be able to get something near the same speed for test purposes. They were cheap, seemed to offer a massive range of options and copious amounts of bandwidth.

How wrong I was. As I was developing my still unreleased super cool app I noticed that the dreamhost email servers were going up and down faster that a 10 year old with a yo yo. Odd, very odd. Then I uploaded my app tonight and holy shit was it slow to upload. Then I began to use her and yes.. it sucked utter balls, too slow.

There seems to be a few factors responsible for the shit speeds. First of all is FastCGI. FastCGI should make my app wiz around like mad, however compared to CGI its basically the same on dreamhost, which suggests a hardware or priority shitness on the servers.

Then there could be database access speed slowing everything down. The database seems to be located on a different server altogether, again noted by others.

I thought it was just RoR on dreamhost that was slow, but no it wasn’t just that. Even if you access via ssh it all seems very sluggish, even doing a “rm -r” on a directory that contained about 20 files took about 10 seconds. Thats just stupid and should be sorted.

Am I expecting too much? A page that takes less than 10 seconds to load?

Perhaps dreamhost is fine for static pages, images and nothing else. Sigh.

Could Ruby and Rails replace Java as a tool for teaching CS in universities?

Friday, February 23rd, 2007

The other night I popped along to the North West Ruby user group, which with some others we bounded around the idea of teaching Ruby in schools and universities over a few beers. Its an interesting thought worthy of exploration.

I remember learning my first programming language at university, it was Java and took so long to build anything. Hours and hours building applets using odd tools to plot a graph and what have you. It was tough but only through my dogged determination I got through it. If we compare this to Ruby on rails where running “scaffold” you can have a working, albeit, simple website engaging with a database. Such speed and ease into programming could prove to be a decisive revelation to the timid and fickle fresher under pressure to use their student loan on the only subject they can be confident in succeeding in. i perhaps would have spent more time working rather than drinking beers and experimenting in .. errr.. stuff if I was taught Ruby.

Its not just the speed and the confidence that this brings but the syntax of Ruby is more ‘user friendly’ than java. As was noted at the group meeting when chatting about Java and “who remembers what public static void main actually means?”. Keeping the syntax simple could leave lecturers and students to concentrate on more concrete and universal ideas of computer science such as OO design and usability something which we all could benefit from.

As for how rails may fit into this, well, it could be used to demonstrate structured design. Notably the Controller, Model, View structure and how beneficial this is to stability, security, design, extendibility and maintenance of an application. As somebody who has worked on too many PHP projects made by others this idea of separating the functional, database and visual elements of an application needs to be taken up by many more people (yes moodle this means you).

I know some of you might be thinking “What? replacing Java with a scripting language, this is a dumbing down of computer science”. An interesting point but as we all know, languages can be learned very quickly when we know the concepts of programming. My argument is that Ruby is syntactically simpler and quicker which in turn make it more engaging for our student to actively learn as compared with Java whilst still offering the same broad range of conceptual ideas.

Of cause this is all arguable, Ruby is still very new and may, as with java, may fall by the weigh side. But it must be clear the UK needs more people engaging in computer science to sustain our dependence on technology. So its important to make the step from novice html builder to programmer an easy an exciting one, java failed to do that with me, but I feel Ruby can.

Some Ruby on Rails blogs

Tuesday, February 20th, 2007

Ok after far too many months not posting anything on here I thought I best put something up. Here is a list of Ruby on Rails blogs that my cool little RSS reader is subscirbed too.