Life on Rails » Technological travels in Flex, Air, RIA and life in general
Imagine a beautiful autumn park, and a bald ginger man reading books and playing guitar, and doing other stuff

Netbeans not just a nice personality

I was googling about and came across this article by Daniel Fischer. I kind of understood what he was getting at and it made me happy because:

a) I take the aesthetics of my working environment very seriously (which was one of the precursors of me leaving windows), and was glad that someone else understands that an IDE should be beautiful,

b) I’d clearly been so in love with netbeans that I had accepted her as “having a nice personality”

It’s true, when I first got netbeans I thought she was rather, how shall we say it…?.. plump, in the gui department. I remember the first couple of days trying to make a few changes here and there.. however, I fell so head over heals for her that I forgot all about this.

Until now.

Daniel called my gorgeous netbeans ugly, and while she’s not the cocoa supermodel that textmate is, I thought that was a little unfair. So, having been familiar with the gui for some time, I decided to trim some of the gui clunk out. Here’s what I came up with: bare gui Click here for a bigger pic

Here’s what I did…

More...

Netbeans THE best ruby on rails IDE

I use netbeans 6, milestone 10 (get it here as my ruby on rails ide now. I’m a mac user, having moved from windows last year.

I was gonna write a blow for blow comparison of netbeans against radrails, but I really see no point. I figured it’s best just to tell you why netbeans’ rails support is so creamingly good, but so you know I have evaluated both and textmate, firstly – here’s some points about the other 2…

Here’s some groovy ruby code completion to wet your appetite. Click more to read the rest of the article:

Image of code completion

More...

Not writing the same js over and over again

I was doing a bunch of rjs stuff in rails, and lots of ajax goodness, and found myself constantly showing, and hiding the spinner and the update element (like a submit button, or other button)..

I’m a bit of a minimalist where possible and like to get rid of as much code as I can, and being as DRY as I can, and so I decided to make the following function:

  1. function updating_field(field_name, finished) {
  2. if (finished) {
  3. $(spinner).hide();
  4. $(update_ + field_name).show();
  5. } else {
  6. $(spinner).show();
  7. $(update_ + field_name).hide();
  8. }
  9. }

I simply call this method from the onclick method, or sumbit method of elements on the page and it tidies up my code considerably.

  1. <input type="submit" value="Save these changes" id="update_avatars2" onclick = "updating_avatars(false);" />

I can then call this code over and over again… In fact, I do, and I have many other helpers similar to this – which I’ll explore in other blog posts.

Script console.

When I was first learning rails I found one thing which helped immensely:

script/console

It’s the bees knees..

  • when you’re starting out it’s like a safe ruby boxing ring where you can spar without getting your butt whooped,
  • as you get a bit better you can practise new moves, and get some essential dojo in,
  • once you know your stuff you can try out some severely funky moves without having to refresh the browser every few seconds,
  • you can always nip into console and get your db sorted, check on db state, sessions, tidy some things up, interrogate your models and find faults, and perfect new bits of code.

I do all my practising, and probably a fair bit of debugging in script/console – if I’m ever doing anything new, or have a new idea it’s the first place I go.

If something’s gone screwy with my app, it’s the first place I go, and when I was starting out – it was ALWAYS open on my desktop.

I’ve written this up because I was just on irc, and for the umpteemth time spreading the word about script/console. Really, go discipline yourself.. Amy Hoy said it far better than this over on slash 7, go check it out:

http://slash7.com/articles/2006/12/21/secrets-of-the-rails-console-ninjas

Blocking IP addresses in rails

I’ve been moving visualchat.co.uk to ruby on rails recently and one of the things they have to do is block certain ip addresses, in fact, entire ranges of ip addresses, as they get a lot of naughty mischievous chilldren (read as fucktards) creating havoc.

I tinkered about a bit and then asked on #ruby-lang where one David Black answered the call. The code he gave me is my favourite bit of ruby code ever. I think his solution is so very nice it’s unbelievable.

More...

Dynamic class instantiation in Ruby

Tags:

I’s on #rubyonrails the other day when someone asked: how do I tidy this up?

  1. def Creation.make(raw, content_type)
  2. if Movie::MIME_TYPES.include?(content_type)
  3. Movie.new(raw)
  4. elsif Music::MIME_TYPES.include?(content_type)
  5. Music.new(raw)
  6. elsif Picture::MIME_TYPES.include?(content_type)
  7. Picture.new(raw)
  8. elsif Fiction::MIME_TYPES.include?(content_type)
  9. Fiction.new(raw)
  10. else
  11. Creation.new(raw)
  12. end
  13. end
More...

Some things I love about ruby

Tags:

Last year (2006) I had some ideas for a couple of websites I really wanted to make.. I had to get some funding together (to pay for food+rent while I coded) and as such, had to write a plan which I could give to money people, to make money decisions.

Part of that involved looking into the technologies in which I’d make my amazing sites. At the time I was a .net developer and was originally going to go down that route.. I was pricing up servers, work estimates, software (18k for sql server!! WTF?!) and eventually worked out I’d need about 100k to do this..

More...

popups and link_to

Turns out that link_to handles popups,

You’d know this if you looked in the rdoc, but if you’re new to rails, you might not be down with that yet.

You can write code like:

  1. <%= link_to "pop me up", { :action => "show" }, :popup => [new_window,height=300,width=600] %>

I’m happier putting a javascript function in myself, and calling that, using onclick=>”popup(‘new_window’, 300, 600);” where function is something like:.

  1. function popup(window_name, url, p_width, p_height) {
  2. var new_window = window.open( url, window_name, "status = 1, height = " + p_height +", width = " + p_width );
  3. new_window.focus();
  4. }

I do this because then I can actually bring the window to the front (or specify more args, etc), I guess it could also be a matter of taste.

In fact, these days, I’m happier not using helpers like link_to for trivial stuff anyhow.

Assignment in expressions

This should be old hat to anyone using ruby for a couple of months, but if you’re fairly new to ruby, and especially if you’ve been kinda, trying to keep afloat in ruby to grok rails, you might not yet know the following

You can assign multiple variables in one expresison in ruby, and as such chain together code to do some seriously cool stuff

Here’s a really simple example:

e = (Event.get_events_in_town t= Town.find(12)).first

This not only sets e to the first event, but also initialises t as that town’s event.

I’m not suggesting you write code like this by the way, but I found this so useful when using console, to debug my apps, or play around with my models