iBrasten

My methods of calculating time are far superior to yours, in every way.

 

This is the blog of Brasten Sager, a software engineer, Mariners fan, guitarist, haphazard philosopher.

27???

April 28, 2006 @ 04:34 AM

Woah, it’s my birthday tomorrow!

Can you believe I didn’t even realize that until this moment? I was reading a David Geller post about Mind Camp starting tomorrow. “That can’t be true,” I thought to myself, “Mind Camp starts on the 29th.” A quick check of my calendar confirmed that, in fact, April 29th is tomorrow. I’ll officially be 27, I think.

My wife got me a couple fun things. I had my heart set on a couple little condiment dishes from Crate and Barrel. Something I found during our wedding registry hunting. We didn’t get them for our wedding so she picked them up for me. Also, she did a great job of getting me a Ruby book! Since she knows nothing of Ruby or programming, I was very impressed! She got me The Ruby Way, and it has turned out to be very helpful already.

Brasten.reflect_on(1.year.ago)

This has been one of the most active years of my life. In chronological order: I got engaged to my best friend, I switched from Java to Ruby as my language-of-choice, I left a job I’d had for 5 years (actually, a reoccuring consulting contract), made a brief pitstop at another job for 6 months or so, left THAT job (to focus on my wedding, mostly), got married, started independent Ruby/Rails development.

There’s still 14 hours left to 26, so I’ll let you know if anything noteworthy happens.

RJS Assertions in the wild

April 26, 2006 @ 11:24 AM

gave RJS Assertions a try and posted a little about his experience.

He does a much better job explaining RJS Assertions than I do, so check out what he has to say.

Gruffness

April 18, 2006 @ 09:17 AM

Well, I spent the last 5 days fighting to get Gruff installed and working. I had begun to lose hope. I literally felt my life force being sucked from me.

But, thankfully, I finally got it working today. I should note that the problem was not an issue with Gruff. I was having some weird conflicts with ImageMagick and RMagick.

Anyway, life is good and happy again, Gruff kicks ass. I made a Gruff graph demonstrating the ordeal.

readonly_forms plugin

April 17, 2006 @ 07:53 AM

I recently found myself solving the same Rails problem for the third time and decided to extract the solution to a plugin. Hopefully this helps someone else.

It’s like InPlaceEditor for a form…

Several of my projects recently have run into the same problem where a the data on one of my views needs to be editable sometimes, and read_only others. The two key requirements were: read-only means displaying the value only, not a read-only text box; and the form had to look largely identical in both states.

To solve this problem, you can either build two identical forms (one with text\_fields, the other without), or you can build one field with if/elses (or something along the lines of: <%= @editable ? text\_field(...) : value %>.

One form for both states…

Using the readonly\_forms plugin, text\_field and select tags now accept :read\_only as an option. If it’s false or nil, the tag operates normally. If it’s “true”, the input box is dropped and the value is displayed instead (in the case of selects, it will resolve the selected IDs with their display values… So you’ll see whatever you would have in the drop-down.)

Screenshots

ead\_only => true

Read Only Form

ead\_only => false (or nil) Read Only Form - Editable

View Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<div class="left pretty_form">
        <label for="customer[company]">Company:</label> <%= text_field('customer', 'company', :read_only => !editable, :size => 20, :class => 'my_new_plugin') %> <br />
        <label for="customer[name]">Name:</label> <%= text_field('customer', 'name', :read_only => !editable, :size => 20) %><br/>
        <label for="customer[title]">Title:</label> <%= text_field('customer', 'title', :read_only => !editable, :size => 20) %><br/>

        <label for="customer[address]">Address:</label> <%= text_field('customer', 'address', :read_only => !editable) %><br />
        <label for="customer[city]">City:</label> <%= text_field('customer', 'city', :read_only => !editable, :size => 15) %><br/>
        <label for="customer[state]">State:</label> <%= select('customer', 'state', Lead::STATES, :read_only => !editable) %><br/>
</div>

<div class="right pretty_form">
        <label for="customer[zip]">Zip:</label> <%= text_field('customer', 'zip', :read_only => !editable, :size => 10) %><br/>

<label for="customer[phone]">Phone:</label> <%= text_field('customer', 'home_phone', :read_only => !editable, :size => 15) %><br />
        <label for="customer[email]">Email:</label> <%= text_field('customer', 'email', :read_only => !editable, :size => 20) %><br />

        <label for="customer[source]">Source:</label> <%= select('customer', 'source', Lead::SOURCES, :read_only => !editable) %><br />
        <label for="customer[referred_by]">Referred By:</label> <%= text_field('customer', 'referred_by', :read_only => !editable, :size => 20) %><br />
        <label for="customer[status_code_id]">Status:</label> <%= select('customer', 'status_code_id', StatusCode.find(:all), :read_only => !editable) %><br />        
</div>

Download

This version works for text\_field and select tags. Other tags will be added later. I will also be adding support for form\_for as a later date.

Cool to the CoR.

April 15, 2006 @ 04:29 AM

I’m back from Canada on Rails! It was really fun. Reflecting after the fact, I think the conference lacked a bit in the socialization/networking aspects. Not that it was impossible, but lunch was the only time you could get any real conversations going, and even that was restricted due to the venue (everyone had to sit in hallways and staircases, etc). There was an afterparty that probably would have been good to go to, but I had to get back to Seattle.

Over all though, it was a lot of fun. I met a lot of great people, ran into a couple people I had no idea would be there, had some great ideas, learn some new things… The Firebug plugin for Firefox was worth the entire trip, for example. :)

RJS Assertions

I added a couple new assertions to the RJS Assertions trunk. They aren’t yet wrapped up into a “release”, but you can pick them up from the repo. Check it out.

We've arrived in Vancouver!

April 12, 2006 @ 05:58 PM

To view more photos, visit my Canada on Rails photoset .

Canada On Rails

April 11, 2006 @ 08:16 AM

Well, AJ and I will be heading up to the Canada on Rails conference on Wednesday. AJ will be flying directly to Vancouver and I’ll be driving up to pick him up.

I’m really looking forward to the whole thing. A lot of very good Ruby or web developers will be presenting, including David Heinemeier Hansson, Thomas Fuchs, the PLANET ARGON gang, Amy Hoy, et al. So this week I will be a sponge, attempting to suck up knowledge anywhere it’s being spilt.

...with thanks to a wonderful wife…

All of this means I will be leaving town on the evening of my wife’s birthday. Of course, this comes just over a month after we got married. Thankfully Jessica understands and is being very forgiving. :) Thanks, babe!

Ruby on Rails Contracts

That title is purely for Google’s sake. I noticed that I’m hitting #4 on Google for “ruby on rails contract”. So, I thought I’d add another post for Google to find. Anyway, I’ve been working on a couple contracts, nothing really to talk about on that front right now.

If you need some Ruby or Ruby on Rails work done, let me know!

RJS Assertions

April 05, 2006 @ 07:04 AM

Testing RJS Templates

I’ve been using RJS Templates very heavily in my recent projects. Of course, if you’ve used them, you know how helpful they can be. But as a unit/functional test addict, I’ve been frustrated by my inability to write really good test cases for my AJAX actions. I’m sure the Rails guys will work something into future versions of Rails, but in the mean time, I’ve thrown together a small collection of assertions that give you pretty good test coverage of AJAX/RJS responses. (Link Below)

Installation

You can install the plugin from your Rails application directory by running:

script/plugin install -x svn://rubyforge.org/var/svn/rjsassertions/trunk

Example

The following example was pulled straight from my current project.

Say you have an action that triggers the following RJS template:

1
2
3
4
5
6
7
8
9
10
11
page.replace_html 'details_column_left',
                  :partial => 'field',
                  :collection => @left_column,
                  :locals => {:values => @field_hash}
page.replace_html 'details_column_right',
                  :partial => 'field',
                  :collection => @right_column,
                  :locals => {:values => @field_hash}
page.hide 'information_save_button'
page.show 'information_edit_button'
page.hide 'field_errors'

The action JavaScript response sent to the browser might end up looking something like:

1
2
3
4
5
6
Element.update("details_column_left", 
               "<label for=\"field[35]\">Preferred:</label>");
Element.update("details_column_right", 
               "<label for=\"field[34]\">Locations:</label>");
Element.hide("information_save_button");
Element.show("information_edit_button");

Using RJS Assertions, you can now assert various conditions on this response. Note the example assertions below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
def test_updating_fields
  post :update_fields, {:id => @joe_schmoe.id, :field => {'1' => 'New Value'}}, logged_in_session

  assert_rjs_tag :rjs => {:block => 'details_column_left' }, 
                 :tag => 'label', 
                 :content => 'Preferred:'
  assert_rjs_tag :rjs => {:block => 'details_column_right' }, 
                 :tag => 'label', 
                 :content => 'Locations:'
  assert_rjs_no_tag :rjs => {:block => 'details_column_left' }, 
                    :content => 'Left Value One!!!'
  assert_rjs_visual_effect 'information_save_button', :hide
  assert_rjs_visual_effect 'information_edit_button', :show
end

It was fairly quickly thrown together for the purpose of a project, so the Ruby code could use a little TLC. Also, I’ll be adding assertions for the various RJS methods in time. If you wish to help out, please visit the RubyForge project page.

Relevant Links

Juanita Village Webcam

April 03, 2006 @ 05:11 AM

I noticed someone stumbled across my blog the other day searching for “Juanita Village Webcam.” I didn’t have one set up, but since I live at Juanita Village, Google must have found something I said. Anyway, it got me thinking, and since I have an extra iSight sitting around, I figured I should put it to good use.

So, my Webcam is back up. And I must say, it’s a much better view than my Edmonds webcam was. The domed building is a Starbucks, and the other building is the Chelsea apartment building. Our view of the water is to the right of the camera, and maybe once in a while on sunny days I’ll point it that direction.

My bad!

April 02, 2006 @ 09:16 AM

Sorry about that. My recent change to the old RSS feed apparently cut off a good 50% of the people who were trying to fetch it, for some reason. Not to mention that it was SLOW. So I completely rewrote the script. It should be much much faster and work for everyone now. Please let me know if it doesn’t!

Welcome back, lazy readers!

April 01, 2006 @ 01:45 PM

I don’t mean that in a bad way. But I noticed that 80% of my “viewers” were still pinging my old RSS feed. Sadly, that means they haven’t been able to read my recent articles! So, I finally got around to redirecting that URL to my new feed!

I apologize if that means you’re getting 10 new articles in your feed reader. :)