Ruby

I got paid (for the first time) to write Ruby today.

A co-worker and I set up a new publications database and used Rails to get up the scaffolding for the website.

Of course, the only real "code" I wrote was to display a list of authors related to a partiucular title. I don't have the code in front of me, but it was something like:

<% for author in @title.authors %>
<%= link_to author.fname+' '+author.lname, :action=>'author_show', :id=> author.id %><%= ', ' unless author === @title.authors.last %>
<% end %>

I had to create the title_controller.rb's "author_show" method, which was something like:

def author_show
redirect_to(:controller=>'author', :action=>'show', :id=>params['id']);
end

...And aside from a "has_and_belongs_to_many" from titles to authors and vice-versa... that was all I had to write to get that functionality (of displaying all the authors for a title).

Of course, I'm a little disappointed that I had to put that "<%= ', ' unless author === @title.authors.last %>" in there. Really what I wanted was a ".join(', ')", but I couldn't get that to work: I'm not familiar enough with link_to and... well... with tying bits and pieces of ruby together.

Even still, the way it is is very readable. (Yeah... that's my excuse, and I'm sticking to it!)

The co-worker that I was helping was very impressed with the amount of ground we covered in the three hours we worked on it, anyway. ...Note that over half that time was wasted trying to connect to the SQL Server database... (Turns out there is not trick to it, just set the type to "sqlserver" and fill out the rest of the fields intuitively!)

On the down side, I was so wrapped up in the project that I totally forgot that I had a date with my wife for lunch--and I was away from my desk, so I didn't get her calls. ...So I'm in the doghouse, now. : | D'oh.

No comments: