Ruby on Rails Tips

How to automagically get friendly URLs in Rails 3

Ruby on Rails Tips

By default, Rails uses ID’s in URLs. For example, let’s say we have a list of categories stored in the categories table of the database. The “Super Cool” category is stored with categories#id = 5. To view that category our URL will look like: http://yourAwesomeDomain.com/category/5 That works great, but it’s not very user friendly. It’s [...]

Read the full article →

Why Your Controller Methods Should be Private

Ruby on Rails Tips

Most of your controller methods are public actions that display pages on your website. Your app’s routes will point to these methods and show the corresponding page (view). For example: But hopefully you are keeping things modular and breaking up complexity into smaller methods. For example, you might want to perform some check before you [...]

Read the full article →

Use Ruby’s ‘autoload’ instead of ‘require’ for your Ruby and Rails Apps

Ruby on Rails Tips

When googling to find the answer to a ruby (or rails) coding problem, it struck me that code snippets always use “require” to include any necessary libraries. For example, I recently searched for a way to compare IP addresses using CIDR notation. (I had IP ranges stored in CIDR notation and wanted to see if [...]

Read the full article →