Archive › Ruby On Rails

Ensuring your join model uniqueness

For example: id |category_id | inventory_id 1 384 1 #first entry 2 384 2 #this would be ok. 3 384 1 #this would not be ok To ensure that a category_id doesn’t have any inventory_id duplicate: [sourcecode language="ruby"] class CategoryProduct < ActiveRecord::Base   belongs_to :category   belongs_to :inventory   validates_uniqueness_of :category_id, :scope => :inventory_id end [...]

Comments ( 0 )

Index your tables people.

A good read on table index. http://www.railway.at/articles/2008/04/24/database-agnostic-database-ignorant Sometimes, it is easy to forget when someone or something else handles it for you. For instance, ActiveRecords. Rails does not  create foreign keys for you. It only creates the primary key. It does not impose constraint on the database level. The association is handled on the application [...]

Comments ( 0 )

Note to self

Do not name your database column with the name ‘no’. You’ll get this error when you try to run your test ActiveRecord::StatementInvalid: Mysql::Error: Unknown column ‘false’ in ‘field list’

Comments ( 1 )

Updating Ruby on Ubuntu 8.04

Pheww.. all test pass after the latest ruby package updates from the ubuntu team. I was a little worried reading the comments from the official Rails site. From the comments, a lot of people are experiencing problems after using the patch provided by the official Ruby team. However, today I received an update notification on [...]

Comments ( 0 )

Nested Layouts in Rails

I was wondering how to keep the layouts in my rails application code DRY – I was close to the point of kicking myself for having to make changes to all my layouts whenever something standard changed – so i researched online and found the above diagram by Matt McCray in his blog. I used [...]

Comments ( 3 )

Rails 2.1 Label

A label method is introduced in Rails 2.1. The following code: [sourcecode language="html"] < % form_for (@post) do |f| %> < %= f.label :title %> #Code truncated for clarity < % end %> [/sourcecode] Would generate the following HTML: [sourcecode language="html"] Title [/sourcecode] If your label contains a css class and if you need another [...]

Comments ( 0 )

Quote Phobia

I don’t get it why some people write this %(Unverified email address. Please check your email for your activation code.) instead of this “Unverified email address. Please check your email for your activation code.” Is it that hard to put those double quote?

Comments ( 0 )

Netbeans

I use Netbeans6.1 when developing in Rails. The thing I like most about it is that I can easily read the docs from a certain method in my code. I just press Ctrl + hover my mouse to that method and walla, the docs appears in my IDE. I can also do that when placing [...]

Comments ( 2 )

Rails 2.1 script/dbconsole

In Rails 2.1, you have a new script/dbconsole Instead of accessing your MySQL database with mysql -u <username> -p You can instead do script/dbconsole and if you database has a password, just do script/dbconsole -p All this works provided that you have the correct database.yml settings.

Comments ( 0 )

Global Email Settings in Rails

I was running the functional test and didn’t realize it was sending actual emails from my data fixtures. However, I did learn how to globally set the email settings so not to send the emails out during tests. If you want to use this, create a file called global_email_settings.rb (or whatever you want to name [...]

Comments ( 1 )