Sterling Rose Design Blog
Dynamic form with a many-to-many relationship
Authored by Dana Jones
May 30, 2009 00:57
1 Comments
Tags: Javascript Rails associations
Authored by Dana Jones
May 30, 2009 00:57
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:
Read the whole post...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 =...
Web Design Resources
Authored by Dana Jones
May 27, 2009 14:48
2 Comments
Tags: web design
Authored by Dana Jones
May 27, 2009 14:48
2 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...* 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
Calculating Line Item Extensions
Authored by Dana Jones
May 25, 2009 14:48
0 Comments
Tags: Javascript Rails Prototype AJAX
Authored by Dana Jones
May 25, 2009 14:48
0 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...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...
assert_include Workaround
Authored by Dana Jones
May 21, 2009 13:51
7 Comments
Tags: testing Rails
Authored by Dana Jones
May 21, 2009 13:51
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:
There may be other ways to do this (and I certainly wel...
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)
endThere may be other ways to do this (and I certainly wel...
Model Component Ordering
Authored by Dana Jones
May 15, 2009 02:19
2 Comments
Tags: Rails community
Authored by Dana Jones
May 15, 2009 02:19
2 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...
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
Authored by Dana Jones
May 12, 2009 20:55
5 Comments
Tags: community WIndy City Rails
Authored by Dana Jones
May 12, 2009 20:55
5 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...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...
Honor the Beginner
Authored by Dana Jones
May 11, 2009 16:06
0 Comments
Tags: career community education RailsBridge
Authored by Dana Jones
May 11, 2009 16:06
0 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.
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
Authored by Dana Jones
May 10, 2009 21:39
2 Comments
Tags: date and time Rails
Authored by Dana Jones
May 10, 2009 21:39
2 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:
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
© 2009<%= "-#{Date.today.year}" if Date.today.year != 2009 %> ABC CompanyIt 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
Authored by Dana Jones
May 09, 2009 16:46
3 Comments
Tags: community RailsConf working from home career
Authored by Dana Jones
May 09, 2009 16:46
3 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...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...
Practical Tips for Attending a Rails Conference
Authored by Dana Jones
May 08, 2009 23:05
0 Comments
Tags: community RailsConf Rails
Authored by Dana Jones
May 08, 2009 23:05
0 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!
Read the whole post...- 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.
- 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...
RailsBridge: Bringing Awesome People Together to Do Awesome Things
Authored by Dana Jones
May 04, 2009 13:36
0 Comments
Tags: Rails community RailsBridge education
Authored by Dana Jones
May 04, 2009 13:36
0 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:
Read the whole post...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.

