Routing in Rails with Unique Column Names
April 25, 2009
A small question popped up while I working with rails today, I’m not sure how well this is documented and it seems fairly straight forward but I feel the urge to share it.
The question is this: how can I route using, instead of a unique id, a different column in a set of data.
Say, for example I have a table with the columns id and name and both are unique. The data contained in my table is:
| id | name |
|---|---|
| 1 | Fred |
The default routing would be as such:
http://localhost/users/1
But what I am after is this:
http://localhost/Fred
How is this done? After playing around here is what I came up with:
Open the routes.rb file and add the line:
map.connect ':name', :controller => 'users', :action => 'show'
So we are passing the parameter :name to our show action in the user controller. Now we need to modify our users_controller.rb to accept this parameter.
def show
@user = User.find_by_name(params[:name])
end
And that’s all there is to it. Look up the Ruby on Rails API for more information on the find_by_ function
I haven’t had much experiance with ruby on rails so if I have said something that may be a little misleading make sure you let me know!
Getting off track with Rails!… Oh!, the puns!
April 18, 2009
Yes, like every other human being who has come across Ruby On Rails there is a strange temptation to start playing with words to show how clever we are but I’m fast to realise that its not the only thing you can do with Ruby On Rails, much to my relief.
If you have no idea what Ruby on Rails is see: http://rubyonrails.org.
Having been introduced to Rails many moons or perhaps about 2 years ago, it had always remained concealed behind a cloud of mystery for myself and as I developed websites for different clients using mainly PHP scripted Content Management Systems I didn’t feel the need to waste time and learn how to use it.
Silly me?
Perhaps so, though at some point there comes the urge to write a new system alot simpler than those systems such as Joomla! or others like it, a system that is tailor made to clients needs and not overloaded with features that have no relavance or are perhaps useless.
Time to removed that cloud of mystery … Enter Ruby on Rails.
Setting Up Rails
I currently am using Mac OS X Tiger 10.4 so I set out to find information on setting up Ruby On Rails.
A brilliant tutorial which has pretty much got me set was from hivelogic:
http://hivelogic.com/articles/view/ruby-rails-mongrel-mysql-osx
Though now with new updates and other current changes there was a few things that triped me up.
- In the Paths section of the tutorial you will see that you are to edit the .bash_login file so that terminal looks in our /usr/local directory though I found when I entered ‘ruby -v’ into terminal it was still showing my old 1.8.2 version of ruby. After scratching around some time on the internet I found that I would actually need to edit .bash_profile instead of .bash_login for terminal to recognise a new path.
- When installing the MySQL native bindings gem using the gem install method it was downloading yet failing to build, again I scratched around the net for a bit and found that due to Ruby Version 1.9.1 I would need to get the latest version of MySQL/Ruby and for some reason gems was only getting version 2.7 and the latest is 2.8 .1 (http://rubyforge.org/frs/?group_id=4550) so I downloaded that tar.gz file and installed it, tested and everything was looking great
I haven’t bothered installing a http server for Rails yet as I am just using the one packaged.
With everything installed, the fun begins…
More on Ruby On Rails comming soon!
Heinkel He-162D Volksjaeger
November 7, 2008
Over the past week I’ve been working on a little project in Blender and now its time to move onto something new, so here it is:
The background matte was made in Photoshop and the model in Blender. If you’re interested in getting into 3D modeling or animation I recommend checking out Blender, you can find it here: www.blender3d.org .
Also I’ve just setup a new CG Portfolio section as well so I’m hoping on expanding that as well.
Enjoy!
Ruby in FlightGear gets a GUI!
October 22, 2008
Boring old black and white text scrolling down a screen isn’t very attractive, right? (Refer to my previous post). So with this on my conscience I set out to give my ruby program, which gets data from FlightGear, a nice pretty interface… well sort of pretty.
So… here it is!
Now when dealing with constant processing of input or output data and in my case it is data being received, as well as a graphical user interface you are asking ruby to do two things at once. In the general scheme of things it is not what simple old ruby does, all it knows is to run through a series of instructions and then either loop back over those instructions or terminate, that being said with exceptions. So let me now introduce threads.
Ruby threads, without going into to much detail, allow multiple processes to run parallel to each other. So I needed ruby to not only be managing the GUI but also receiving and processing I/O data and thus the use of threads.
Setting up a thread is quite simple:
And you can find more information about them in the ruby core libraries documentation, see here.
Like the rest of my programs featuring GUI’s I have a soft spot for FXRuby, and I really don’t know why but I think it is mainly because it works, strangely enough. To allow me to update each piece of information (speed, altitude, etc.) I used FXRuby’s Data Targets which I setup to be updated from within the threaded receiving process.
All in all it is a pretty straight forward program but there are still plenty of loose ends needing to be tied up before I can call it a completely finished. It doesn’t even fulfill its intended purpose yet so there is plenty more to do.
If anyone is interested in the complete ruby code post a comment (with your email address) or send me an email and I will forward it on to you.
Stay tuned for more!
Ruby, IronRuby and FlightGear – The Perfect Trio… maybe
October 21, 2008
Ruby, IronRuby and FlightGear; Three big subjects in their own rights but here I am mixing them all together and perhaps getting into things a little to much over my head.
The idea of using these three programs is to get real time data from a flight simulator program and then process and output it through ruby. Also a future goal is to be able to send data to control different systems while in flight through external components.
The following post contains information on FlightGears .xml protocols and configuring the simulator to output data through a socket. Also two scripts in Ruby and IronRuby which gets data from FlightGear and displays it.
Please also note that you will find that some information I give is similar to what is given at http://linkslink.wordpress.com/takeoff/ as I used the information as a guide when I was learning about the .xml Protocol files and has led me to some handy .Net libraries when using IronRuby.
QANTAS and its shiny new toy
October 11, 2008
It just so happens that the glide slope on the approach to Brisbane’s Airport is directly over where I do my training for avionics so I caught the QANTAS A380 on its final approach. Unfortunately I didn’t have my trusty point and shoot camera so I had to use the one on my phone. I apologize for the bad images.
The Bench-top Power Supply
October 11, 2008
So here is yet again another infrequent post in this mess called a blog. If I was a reader of it I would have lost interest long ago and forgot the address to this site but then again I am just one of those impatient sort of people. Yet with this in mind I do endeavour to be a little more constant with my posts. I have tried to make things a little bit more interesting by adding a new section which has got some of my photography of aircraft and aviation in general which I hope you enjoy.
Anyway by now you are asking why I named this post The Bench-top Power supply so I’ll get straight to the point: I needed something to do… so I made a Bench-top Power Supply. There are plenty of other things I could of made which would have been much more stimulating and interesting but the fact is having a variable power supply is so handy and I would add a few small features which I find come in handy.
I have used a standard step down transformer (240 VAC to 15 VAC), a bridge rectifier kit and a voltage regulator kit from Jaycar (www.jaycar.com.au). So thats the basic idea to a power supply, I then added terminals to plug in a dc supply to be regulated (i.e. Car battery) and a toggle switch to select between the ac and dc sources. I then added a tie switch which allows the power supply to be either floating, positive tied to earth or negative tied to earth. Call me lazy but it saves the extra wire to do the tying for you.
I hope to be a little more frequent now with this blog but no guarantees as I’m coming to the end of my avionics course so I’m a little busy. Anyways, Enjoy.
The Digital Harp…
August 14, 2008
This little project has been in the making for a couple of weeks now and finally it is completed, so here it is and I hope someone out there can find this information helpful atleast.
So what is the digital harp? Well the idea evolved from a thought train of creating a dynamic and complex music instrument that could be controlled by the fingers yet while not touching a single string/key/button/pie and produce a vibrant and beautiful sound. So after a bit more thinking I came up with a compromise to my ambitious thoughts and
managed to bang together a digital harp consisting of four “digital” strings, a ukulele and a very very simple synthesizer.
So very simple.
Using four LDRs and a voltage divider circuit which a transistor sensing the increase in voltage drove a solid state relay I was able to create a very small and easy control circuit for when a hand moved in front of the LDR and blocked its light source from the laser.
I created the oscillator using a 7414 chip which is a Hex Inverter with Schmitt trigger inputs and put a resistor in between the input and output legs and a capacitor. This oscillator provides a square wave output, unfortunately square waves don’t produce the best quality sounds but for this project it worked okay, though if you have the time and the parts I would recommend building a sinusoidal wave oscillator as they sound a lot better.
I setup four of these oscillators for each of the digital strings and then their outputs into the one amplifier.
This is the square wave oscillator setup:
Then its just fitting everything together onto the ukulele which was basically done using a hot glue gun. I removed the nylon strings and tuning pegs, put a on/off switch on the side with a LED… its not a real project if there are no LEDs, and fixed a 6.5mm audio socket to it as well so I could plug it into my guitar amplifier.
I haven’t drawn up an official schematic yet but I do plan to in the near future… if anyone is interested in it let me know, it might just help with motivation.
There are a few little problems with it at this stage but it is practically working as expected and is a great little tool to annoy friends.
Until next time!
Finally… A combination lock!
May 17, 2008
For about a year now I have been wanting to build a combination lock with the PIC16F84A so finally here it is, very simple as it is yet the important thing is that it works.
I built it from the schematic from this website: http://jap.hu/electronic/combination_lock.html:

The hex and asm code can also be downloaded from the website to program the pic with. For this initial setup of the combination lock i made a few modifications to the design which involved taking out the 5v regulator and replacing it with a 5v1 diode, removing the relay and transistor setup and replacing it with a simple L.E.D and also getting rid of LED1. The crystal I used was a 3.578 MHZ crystal. The main purpose for all this is just to make sure the PIC is being interfaced with the keypad correctly and is acknowledging a password being entered in and being able to change its password stored in its memory. Which, believe it or not – works! <insert a little dance here>

So now that everything looks dandy on a basic level the goal is to have a combination lock that is interfaced with a computer, allowing a number of parameters of the lock to be changed via pc as well as passwords and a log of what has been entered on the keypad and any successful or unsuccessful entry attempts. Anyway thats hopefully where things are heading!
Stay tuned for more mystical, world domineering and pointless projects.
A laptop without power is not a happy laptop
May 16, 2008
This time not a pointless project and for that I am so sorry but I feel that it may be of some help to others who come across a problem similar to this one. The problem was an Acer Aspire 3681WXMi whose battery didn’t charge and wouldn’t run off external power… now there is obviously only a few things which could have been at fault in this case: 1. Power Supply 2. Power Supply Socket on Motherboard or 3. Motherboard. Now skipping past all the testing and troubleshooting it turned out to be the power supply socket on the motherboard and wahoo! to any Australian who can get a replacement locally. In the end I decided to go for the quick fix which essentially works anyways so long as you aren’t in for any flashy look.
I took to the socket with a pair of pliers, then made my own beautiful plug <insert the rolling of eyes>.


So there we have it, not the prettiest repair but it works.
Also just a couple of things to note with the blog, some of the images are not being displayed due to their hosting being closed down so I hope to have them re-hosted soon.
Apart from that hoping to have some more stuff up here soon!












