Sterling Rose Design Blog

Freelancing: Writing Estimates

5 Comments
Tags: career freelancing

I get asked this question a lot: How do you write a proposal for a freelance contract development job?

First, it’s important to understand that freelancing is a different animal from working for a larger development firm (or, as I lovingly think of them, a Dev-in-a-Box). We have some considerations as independents that they don’t, and vice versa, so I don’t presume to know how best to bid jobs if you’re the Thoughtbots or Hashrockets of the world.

But if you’re an independent developer, then these tips may be useful for you.

1) Never, ever, ever bid flat-rate. Nobody is that good at estimating the time it takes to develop an application, and you will almost surely be wildly over or wildly under the amount of hours it takes you. Also, the client who knows you aren’t going over $X will tack on as many new features to the spec as you will allow them to, since they know it can’t cost them any more. Someone ...
Read the whole post...

Dynamic form with a many-to-many relationship

1 Comments
Tags: Javascript Rails associations

My customer’s application is an in-house ordering system (among other things). The order form has a drop-down list to select the client placing the order. It also has two other drop-down lists: primary_contact_id and secondary_contact_id, both of which are based on the Contact model. My customer is certain he will only ever need to associate two contacts with an order, so I’m comfortable with this approach.

The sticking point was that I only want to populate the primary and secondary contact select boxes with contacts that are associated with a particular client. Client and Contact have a many-to-many association.

Ryan Bates’ Dynamic Select Menus Railscast got me most of the way there, but his example (countries/states) was one-to-many, not many-to-many. Following was my adaptation:

views/javascripts/dynamic_contacts.js.erb

var contacts =...
Read the whole post...

Web Design Resources

108 Comments
Tags: web design

I don’t consider myself a designer – I self-identify as a developer – but since I’m the only coder on most of my projects, I have to fake it sometimes. Over the years, I have bookmarked a lot of sites that I find more useful than others in doing the design work. They include:

* Bazaar Designs – Links to incredibly rich, detailed stock photos and really unusual font choices available for download and use, as well as great tutorials and blog entries on other subjects, like CSS and AJAX.
* COLOURlovers – Suggestions of color palettes to use for site designs, plus downloadable tiling patterns.
* Da Button Factory – Generate custom buttons on the fly for use in your applications.
* Dry Icons
Read the whole post...

Calculating Line Item Extensions

84 Comments
Tags: Javascript Rails Prototype AJAX

In my project, I have orders, and each order can have an unlimited number of line_items. Line_items are created by the user clicking on a button, which appends (via RJS) a new row to the line_items tabled form. So far, so good.

But I needed the extended price (quantity * price_per) of each line_item to be calculated every time the user tabbed out or clicked away from the price_per field. Further, I needed the subtotal, tax, total, and balance fields to be automatically re-calculated.

I messed around with it for several hours, trying Javascript, Prototype, and even jQuery, before I finally settled on a Prototype approach that worked. The real struggle was that using Rails 2.3’s nested forms functionality meant that each line_item would have an index key embedded in the middle of the text field’s name and id, and I could not come up with a good way to extract it, to pass it to the Javascript function.

Luckily...
Read the whole post...

assert_include Workaround

7 Comments
Tags: testing Rails

I’m not sure if there used to be an assert_include method or not (I’ve seen some references to it, but can’t find it anywhere in the Rails API), but I found a workaround.

I have a Color model, and I want the :index action to only show those colors whose deleted value is set to false (it’s more or less what the acts_as_paranoid plugin did/does). My test for the :index action looks like this:

test "should get only colors that are not deleted" do
  first_color = Color.create(:name => 'Blue', :deleted => false)
  second_color = Color.create(:name => 'Red', :deleted => true)
  get :index

  assert_response :success
  assert_not_nil assigns(:colors)
  assert_equal true, assigns(:colors).include?(first_color)
  assert_equal false, assigns(:colors).include?(second_color)
end


There may be other ways to do this (and I certainly wel...

Model Component Ordering

81 Comments
Tags: Rails community

On a whim, I asked (in IRC and via Twitter) what order – given validators, accessors, and associations – developers typically listed these components in their models. As far as I know there is no compelling reason to use one order over the other (but feel free to correct me in the comments). Even so, it can be fun to know what other developers do.

I had 19 responses, broken down as follows:

Accessors | Associations | Validators = 20%
Accessors | Validators | Associations = 5%
Associations | Accessors | Validators = 20%
Associations | Validators | Accessors = 45%
Validators | Accessors | Associations = 5%
Validators | Associ...

Childcare at Windy City Rails

16 Comments
Tags: community WIndy City Rails

I was fortunate to run into Ray Hightower as we both left the TDD BoF at 10PM one night. I was pretty wiped out by that point, but was still excited to find out that I was talking to the man behind Windy City Rails.

We had a great discussion on our way to the elevators, about conferences and how to get more women in attendance at them. I mentioned one thing that had come out in the Women in Rails panel as a suggestion: childcare at events. I am of the opinion that having childcare available at conferences, workshops, and other events will be a huge win for families in general, and perhaps women in particular. Ray was very enthusiastic about the idea, and actually followed through on researching childcare alternatives for WCR!

The Westin – which is host...
Read the whole post...

Honor the Beginner

6 Comments
Tags: career community education RailsBridge

I am a martial artist, and try to train either body or mind every day.

Today I was reading a page from Bow to Life: 365 Secrets From the Martial Arts for Daily Life and the lesson really struck home for me in terms of my work with RailsBridge.

(Beginners are) your opportunity to participate and bring more goodness into life. Beginners let you empty your cup while filling theirs. They are life’s way of vaulting you to higher consciousness and better living.

Look for opportunities to share your expertise with others. Treat each opportunity as a learning experience for yourself. Ask yourself why life has sent you this particular person at this special time. What aspect of sharing your expertise is connected to your o...

Perpetual Footer

48 Comments
Tags: date and time Rails

I was spinning up a brand new client website that would (like most websites) include a copyright footer. I wanted to make sure I wouldn’t have to come back year after year and update the year span, so here is what I used:

&copy; 2009<%= "-#{Date.today.year}" if Date.today.year != 2009 %> ABC Company


It will display only 2009 as the copyright year until January 1, 2010, then it will start displaying a span (from 2009 through the current year). Simple.

Uses Rails 2.3.2

Being More Visible

15 Comments
Tags: community RailsConf working from home career

RailsConf was inspiring on so many levels, it would be almost impossible to try to cram it all into one blog entry, so I won’t even try. So for this entry, I want to talk about what I took away from the event in terms of being a female developer in an industry that is overwhelmingly male in its constituency.

Before about three weeks ago, I didn’t really think about it much. I was a “coder who was female”, not a “female coder.” The “girl” part was at best incidental. I mean, sure, I knew that I was in the minority in the #rubyonrails IRC channel, but it was a non-issue for the most part. Now, I’m more conscious.

There were about 40 female and about 1100 male attendees at RailsConf 09. That’s a ratio of about 3.6%. I saw and heard (via the #railsconf IRC channel) plenty of guys call it a “sausage-fest.” And it was. Now I’m not abou...
Read the whole post...

Practical Tips for Attending a Rails Conference

2 Comments
Tags: community RailsConf Rails

I just finished attending my first-ever RailsConf in Las Vegas, NV. It was an amazing experience that I’ll be blogging about a lot over the next coming days. I wanted to make my first post on the subject be a (long – sorry) list of tips and advice in case you ever plan to attend a similar event yourself. If you have tips of your own that you’d like to share please feel free to drop them in the comments section!
  1. Bring lots of business cards. One of the greatest benefits of attending a conference of any type is the contacts you will make, and it’s easier for them to remember who you are and keep in touch if they have your contact information.

  2. Take care of your feet. There is a lot of walking and standing, and the days are quite long. Wear very comfortable, well-padded shoes. Put your feet up when you can. If you can find a place to unobtrusively take your shoes of...
Read the whole post...

RailsBridge: Bringing Awesome People Together to Do Awesome Things

2 Comments
Tags: Rails community RailsBridge education

Over the last couple of weeks, a motivated group of people took the See a need, fill a need approach to development in general, and the Rails development community in particular. The needs we saw were:

a) Make a concerted, focused effort to encourage a sort of “culture of kindness,”
b) Promote a “give back” mentality by developing applications in Rails for non-profit organizations,
c) Support greater inclusion of all kinds of minorities, and
d) Provide a wealth of documentation, mentorship, and instructional material to new developers.

With those objectives in mind, we have launched RailsBridge. Our guidelines are pretty simple:

* First, do no harm. Then, help where you can.
* Bridge the gap from aspiring developer to contributing community member, through mentoring, teaching, and writing.
Read the whole post...

Review: Timeboxed

10 Comments
Tags: time reviews

I’ve been using timeboxing for a little over three weeks now, off and on, and I continue to find it a very useful technique for my own working environment.

Yesterday, I received an email from someone at Macmation about their product, TimeBoxed.

TimeBoxed was designed to be extremely simple to use.
Each of its features has been carefully designed and configured to adhere to the core mission of this application.
In fact, many features were discarded because they just couldn’t live up to our stringent mission requirements.
The result is an application that does exactly what you need, the way you need it.


The install went off without a hitch and took about 30 seconds after the download.

Ti...<br />
		</div>
		
			<span class=Read the whole post...

Timeboxing

2 Comments
Tags: working from home

Yesterday, I tried an experiment in time management. I am always working on at least a dozen projects (professional and personal) at a time, and was feeling as though a) I wasn’t getting enough done, b) I was distracted even while working by all of the things I hadn’t finished yet, and c) time just kept getting away from me. So I decided to try a little timeboxing, in conjunction with #dailygoals.

The basic concept was this: Via the #dailgoals Twitter hashtag, I define what projects I want to work on that day. I stayed away from saying I wanted to complete anything but the most insular of tasks (placing an order, for example) and left everything else open-ended. Then, I whipped out my handy-dandy timer application, Apimac timer (I’m sure a kitchen egg timer would work just as ...
Read the whole post...

Using AJAX to Change a User's Role

2 Comments
Tags: Rails AJAX

Scenario: Client wants to display a list of users, and the role each user currently has. The user’s role should be the selected option in a select box of all roles. Administrator should be able to update the user’s role by simply selecting a new role from the select box for that user, without having to reload the page.

Approach: Each row in the user’s list should have an id that uniquely identifies it as being associated with that particular user. Each select box should also have an id field associated with the user. Choosing a new role should trigger the onchange event, which executes the update on the role and displays the new user’s row in place, without reloading the entire user list.

Code:

## app/views/users/index.html.erb

 <table>
   <% @users.each do |u| %>
     <tr id='user_row_<%= "#{u.id}" %>'>
       <td><%= link_...
Read the whole post...

eWeek Covers Rails 2.3 RC 1

5 Comments
Tags: Rails media

Darryl K. Taft of eWeek asked several of us who tweet about Rails what we thought about yesterday’s release of Rails 2.3 Release Candidate 1. Here is the article, along with my own thoughts.

Rendering datetime in a user's timezone

6 Comments
Tags: Rails date and time

We recently had a client who wanted to account for a user’s time zone when they entered dates for various fields. For example, if a user were to input a new bill, the bill entry date should default to the current date. Time.now is what we had been using, but that would only give the right date if you were on the correct side of the magic UTC dividing line.

The solution to this problem involved 1) storing a user’s time zone in a string field in the User model, and 2) adjusting Time.now for that time zone.

For part 1, we used Rails’ built-in time_zone_select method:

<%= form.label :time_zone, "Time Zone" %>
<%= time_zone_select :time_zone, @user.time_zone, nil, :default => 
  "Pacific Time (US & Canada)" %>


For part 2, the solution was to add a method to the User model to get the user’s current date:
Read the whole post...

Does the world really need another Rails blog?

16 Comments
Tags: announcements

After a few weeks of coding it, I’ve finally kicked off my first purely “professional” weblog. I’ve been coding in Ruby on Rails for a little over a year now, and decided it was about time for me to start sharing some of the things I’ve learned and discovered and figured out.

This is not a news/announcements aggregation site. There are plenty of those out there, doing it much better than I have the time for.

So what are you likely to see here? Code snippets, tutorials (probably starting with a series on how to build a blog just like this one), obscure API documentation, mentions of plugins I’ve found useful or cool, etc. I plan to focus on some of the most commonly-used web functionality, with focus on doing things “the Rails Way” as much as possible.


Copyright 2007-2012, Sterling Rose Design. All rights reserved.