I have some tables that I am populating from a CSV file and it took me a little while to work out where to unpack the contents of the file. In the end, it was obvious that the place for it was in the model. In realising this I had the epiphany (again!) that controllers should really be kept very, very simple.
As David Kaneda explains in the jQTouch blog, he introduced a tap
custom event to remove a 300ms delay when tapping on a link in Mobile Safari.
Rails application templates allow me to automate the setup of each new Rails application, so I don’t have to repeat all the steps required to get an application running the way I want it.
When adding jQTouch files to a web a page, order matters.
I have a Rails-driven website which changes infrequently and contains mostly static content. It is cheaper and almost as convenient to run it as a static site than to run it as a Rails app.
In any block of code, execution is sequential. Each line of code will not execute until the previous line has executed. If a line contains a function call, then the next line will begin execution after that function returns a value. If the function continues to execute code even after it returns a value, then the code in the original block is no longer executing sequentially, in other words two different blocks of code are running concurrently. Concurrency is generally achieved in software by some implementation of threads.
A few notes to myself on developing on OS X 10.6 (snow leopard).
I have been tinkering with MongoDB and the MongoMapper gem for Rails and creating a MongoDB-based Rails project is pretty easy.
Some comparisons of ActiveRecord method calls and the equivalent SQL for associations, starting simple and progressing to joins and chained joins.
You can use the .irbrc file to make changes to the Rails console. My .irbrc file currenlty looks like this:
A few reminders to myself of how to keep Rails applications simple.
I came across a situation where I thought I wanted to access the current_user
from within a model, but it was just a case of mistaken thinking. Making session variables like current_user
accessible to a model is a break with convention, and breaking with conventions is usually a bad idea. So, the rule is: don’t do it unless you have exhausted all other options. There is a probably an easier way of doing what you are trying to do.
I have a tendency to multiply layouts in Rails, so that after I have defined the main application layout in /app/views/layouts.application.html.erb
, I create different layouts for different controllers as needed. That’s all OK, except that I find myself cutting and pasting from the application layout which is just wrong, wrong, wrong.
REST is now the standard way of doing things in Rails and I am a convert. I have always spent far too long worrying about the best way to write my applications, but now REST has come into my life and taken a whole universe of procrastination and indecision away from me.
Rails offers the html_escape
method (usually shortened to h
), which prevents simple attempts at code injection. However, when users are entering content onto a site, there is a very good case for sanitizing the input. After all, if a rogue user is injecting unwanted code into my HTML forms, why would I want to store it in my database? It makes sense to neutralize it before it gets stored.
Named scopes in rails make for tidier code.
When I save data in Rails, I continually misuse the different methods available, so that my code is sprinkled with save
, save!
, save(false)
, update_attribute
, update_attributes
and so on. I also often introduce bugs by assigning a new value to an attribute and then forgetting to update it.
This may seem trivial to some people, but I got a bit confused finding a path through the Restful Authentication plugin for Rails.
Text-to-voice software and synthesised voices are getting to the point where they are really quite impressive and certainly usable. I recently discovered Acapela’s range of multilingual voices and I want to use them. However, accessing a computer’s voices from within a web page is not entirely trivial.