Main

Ruby on Rails Archives

October 16, 2007

Ruby on Rails built in string shortcuts

There are some great string munipulation shortcuts in rails. I thought this was a good write up and little collection of some of the most useful functions.

Rails string shortcuts

September 7, 2007

Always use lenth on ruby collections

This bug never got me, but it is a good little ruby best practice to follow. So remember when ever using ruby collections use .length call not the .size call...

Why use length on all ruby collections.

August 12, 2007

Finished Rails Book

I finally finished a reading the rails book all the way through. I keep putting it off and reading other books because reading straight through a programming book is boring. Yippie for finishing that up, and I learn some more little rails tricks that should be helpful.

Next up Linux System Administration and Backup and Recovery!

July 31, 2007

Using Rails link_to_if

There are a lot of great helper methods in rails, and I need to remember to use more of them, one I over looked for a long time that I have found useful is link_to_if

<%= link_to_if logged_in?, "#{item.name}", :controller => 'items', :action => 'show', :id => item %>

replaces the much longer and more verbose:

<%- if logged_in? %>
<%= link_to , "#{item.name}", :controller => 'items', :action => 'show', :id => item %>
<%- else %>
<%= item.name %>
<%- end %>

I like being able to replace five confusing lines with one single simple solution. The link_to_if helper writes a link if the condition is met, otherwise it just outputs the text that would have been in the link. Very cool.

Also if you want to use Ajax forms with multiple submit buttons in Rails, here is the solution.

Lastly if you are trying to write a selector and want to make sure the test is returning the html you expect you can add puts @response.body into the test after the page call and see the response. This has been useful to me a few times.

June 26, 2007

Highly useful assert_select

I find myself using the assert_select a lot while doing testing and rails. I have had to keep looking up different examples depending on the situation. I have found that this page seems to have most everything I need when I can't remember it off the top of my head.

Rails assert select examples

July 10, 2006

Ruby on Rails Gem error could not find gem

I got this gem error on Ubuntu 6.06 over and over then finally I followed these instructions to install Ruby on Rails,

Install Ruby on Rails on Ubuntu 6.06

and I changed one line:

sudo gem update --system IS WRONG!!!!

run:

sudo gem update

and thing all the sudo gem installs work perfectly fine for me. Why I have no idea. I hate computers sometimes, but at least ruby and rails now work for Ubuntu 6.06 on my system.