Simple auto-complete in Ruby on Rails

The Slash7 tutorial on Ajaxariffic Autocomplete with Scriptaculous was helpful, but it is a bit outdated, considering that it is from 2005.

You’re going to want to download the latest version of Scriptaculous directly from its website – the article links to the current version at the time of writing, in 2005.

The Ruby pieces that it suggests using (text_field_with_auto_complete and auto_complete_for) were moved to the auto_complete plugin in Rails 2.0. You can install this using the command “ruby script/plugin install [URL on github page]“.

Per the plugin’s wiki, you need to use text_field_with_auto_complete‘s fourth parameter, :method => :get, or you will continually have authentication token errors like I did and potentially be redirected to your app’s login page!

Editing the CSS isn’t as easy as she suggests – it’s now put directly into the page (bad design!). I took the CSS out of vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb (it’s near the bottom of the file in my version) and put it into my normal stylesheet, so that I could edit it more easily.

I didn’t like how the default CSS has the auto-complete box appearing over top of the text field, so I added the following two lines to div.auto_complete:

  • margin-top: 15px;
  • margin-left: 8px;

And now, I have a very simple auto-complete that populates my text field from data in the database that is already in the text field! The next steps are to figure out a) more complex auto-completion with a hidden ID field and b) how to do something based on the auto-complete result, i.e. populate other fields.

Posted in Ruby on Rails | Tagged | Comments closed

Calendar in Ruby on Rails

One of the things that I like about working with Ruby on Rails is that it’s really easy to find a plugin for something you’re trying to do, instead of having to re-invent the wheel.

Petrik de Heus has written a beautiful plugin for building a calendar using HTML: table_builder plugin on github

It takes in a collection of objects which relate to a date and builds it according to the template you specify.

Posted in Ruby on Rails | Tagged | Comments closed

Early 401(k) Withdrawals – Worth It for the match?

Some enter a 401(k) plan with the assumption that we will withdraw the full balance after leaving the company. Some choose to not contribute to a 401(k) plan to avoid the hassles of withdrawing it later in a lump sum.

As a non-US citizen or green card holder, I do not plan on retiring in the US. I am not ruling this out, but I do not plan on retiring in the US at this time. As such, I need to evaluate a prospective 401(k) plan differently than my American colleagues. My evaluation isn’t simply Roth versus traditional or how to split between the two, but also 401(k) or taxable account?

Questions:

(1) Will a Roth 401(k) or a traditional 401(K) offer me a better return?

(2) Will a taxable investment account or the 401(k) option chosen in question (1) offer me a better return?

Assumptions:

(1) My employer provides both a traditional and a Roth option in its 401(k) plan.

(2) My employer provides an identical match with both the traditional and Roth option in its 401(k) plan.

(3) I am in the same marginal tax rate at the time of contribution and the time of withdrawal.

(4) After leaving my current employer, I withdraw my entire 401(k) balance and return to Canada.

(5) I will leave my current employer before I turn 59 1/2.

(6) I would contribute the same amount to the account that makes the most sense, regardless of if it is a Roth 401(k), traditional 401(k), or taxable investment account.

(7) Any additional funds beyond the funds assumed in assumption (6) would be invested in a taxable investment account and are outside of the scope of questions (1) and (2).

(8) I would make the same investment choices with the same expense ratios and commissions across all three options.

(9) I only receive the match from my employer if I contribute to the 401(k) plan.

Facts:

(1) The taxable portion of the distributions from a 401(k) plan is subject to the 10% early withdrawal penalty.

(2) The employer match is invested in a traditional 401(k) account regardless of whether my contributions are marked as traditional or Roth.

(3) A distribution from a traditional 401(k) account would be fully taxable.

(4) Only the earnings in a distribution from a Roth 401(k) account are taxable. (Plus the balance of the traditional portion.)

(5) Trading in a 401(k) plan does not incur any taxes.

Hypothesis:

(1) If I do not plan on staying at my employer for long enough to be fully vested in the match or my employer does not offer matching with its 401(k) plan, I should invest in a taxable investment account and not in my employer’s 401(k) plan.

(2) Barring hypothesis (1), I should invest in my employer’s Roth 401(k) plan enough to get the full match.

Calculations:

Question (1):

(a) As per facts (4) and (1), with a Roth 401(k) plan, I would only pay taxes and the early withdrawal penalty on the earnings and the balance of the employer match portion.

(b) As per facts (3) and (1), with a traditional 401(k) plan, I would pay taxes and the early withdrawal penalty on the entire balance of the account.

Question (2):

(a) The employer match should be treated as additional income that compounds and is taxed at withdrawal. By foregoing 401(k) plan, I am essentially taking a gross pay cut in the amount of the potential match from my employer, compounded over the number of years that I stay with my employer.

Conclusions:

(1) The taxable and penalty-addressed amount in calculation (1a) is lower than the amount in calculation (1b), thus the Roth 401(k) plan is a better option than the traditional 401(k) plan.

(2) Contributing enough to a Roth 401(k) plan to receive the full match from my employer is a better return than investing solely in a taxable investment account due to foregoing the 401(k) plan being comparable to taking a pay cut in the amount of the potential match from my employer.

Follow-up Questions:

(1) Is it correct that you do not pay the 10% early withdrawal penalty on Roth contributions?

(2) Will contributing the maximum to a Roth 401(k) offer me a better return than investing the same amount in a taxable investment account?

Posted in Finances | Tagged , , | Comments closed

2010 in Review

  1. I received my Bachelor’s degree.
  2. I had laser eye surgery, resulting in 20/15 vision after wearing glasses since the age of 7.
  3. I attended my first baby shower.
  4. I went to a Winter Olympics event.
  5. I relocated to Seattle to start a new job and furnished my first real apartment.
  6. I spent a month working in Paris in the spring.
  7. I walked across the stage at my alma mater’s undergraduate commencement ceremony.
  8. I spent 6 weeks working in Paris in the fall.
  9. I bought a new car (my first).
  10. I spent a good portion of my non-working, non-sports hours in November and December working on a personal project using Ruby on Rails that I now actively use.
  11. I renewed my lease on my apartment, another first.
Posted in Personal | Tagged | Comments closed