01
Nov 09

Carbon fiber bits

june172008015oi8

Maybe I’ve watched the Fast and the Furious a few too many times, because I REALLY love carbon fiber. It’s just so…sexy. What I don’t love is it’s price tag. I’ve always been a DIY kind of guy, so I figure I’d give this a shot. I did a wet lay of the RS4 front lip and my existing B pillars. Let’s just say…it was a learning process.

Note: the spoiler on the RS4 is not mine, just a photo for inspiration


30
Oct 09

Using a Rails collection partial with a counter

I was reworking an application today and noticed there was a portion of the code that was rendering a counter.

# what I saw
<% @wheels.each_with_index do |wheel,count| %>
  <%= render :partial => "wheel", :locals => { :wheel => wheel, :count => count} %>
<% end %>

# you might also be doing
<% count =0 %>
<% @wheels.each do |wheel| %>
  <%= render :partial => "wheel", :locals => { :wheel => wheel, :count => count} %>
  <%= count += 1 %>
<% end %>

Instead of using a block and rendering the partial each time, let’s try something different. We’ll use:

<%= render :partial => "wheel", :collection => @wheels %>

This will allow us to iterate through each item in our @wheels collection. Rails will make each element available to the wheel partial using the “wheel” variable. If our partial was “book” our variable would be “book” as well. If you want to change the name of the variable, you can do this:

<%= render :partial => "wheel", :collection => @wheels, :as => "dinosaur" %>

Now that we’re rendering a collection, we have a helper available to us inside of the partial that returns the index. For example:

# in our view
<%= render :partial => "wheel", :collection => @wheels %>

# in our wheel partial
# returns index
<%= wheel_count %>

# another example:
# in our view
<%= render :partial => "page", :collection => @pages %>

# our page partial
# returns index
<%= page_count %>

11
Oct 09

Multiple database connections with Rails

Recently a client requsted that I add a new admnistration panel to an existing Rails application. I thought to myself, “That sounds simple enough?”; welll, things are never as simple. In addition to this control panel, they wanted to use an existing MySQL database and its contents which, of course, did not follow the Rails naming conventions. Anyhow, after some research here is what I came up with.

Our first stop is in the database.yml file; the file should look something like this:

# database.yml
development
:
  adapter
: mysql
  encoding
: utf8
  username
: root
  password
:
  database
: example_development

This shouldn’t be a suprise to you. The database specified above is the default database that all of our Active Record models will use; if we want to add another connection we will need to start by speficing the connection. This connection can be another MySQL, PostgreSQL, or even an Oracle connection.

# database.yml
development
:
  adapter
: mysql
  encoding
: utf8
  username
: root
  password
:
  database
: rails_development

# here we specify new connection
pixel_development
:
  adapter
: mysql
  encoding
: utf8
  username
: legacy_username
  password
: legacy_password
  database
: legacy_database

Now that we have the connections specified, we need to move to our model; it is in here where we redirect the request to a non-standard connection. I have created a new model called “Pixel” which will interface with a database used for tracking pixels.

# app/models/pixel.rb
class Pixel < ActiveRecord::Base
end

Unless we specificy another database connection, Rails will use the default enviroments database; in this case “development”. Let’s change this by adding the following line:

# this will use our "pixel_development" database
class Pixel < ActiveRecord::Base
  establish_connection :pixel_development
end


# but let's make this more dynamic so we can use
# develpoment, production, and test databases
class Pixel < ActiveRecord::Base
  establish_connection :pixel_#{RAILS_ENV}
end

Now we should be good to go! Any requests to the Pixel model will connect to the second database. Say the table name is set in stone and cannot be modified? No problem.

# this will use our "pixel_development" database
class Pixel < ActiveRecord::Base
  establish_connection :pixel_#{RAILS_ENV}
  set_table_name "your_table_name_here"
end

15
Sep 09

18×10 Volk TE37s

My 18×10 Volk TE37s track wheels came in today. We had a chance to test fit the Alcon kit, and everything clears! The TE37 weighs in at 19.45lbs without the center cap.


13
Sep 09

Cisco VPN and Snow Leopard

After upgrading to Snow Leopard 10.6 I’ve run into yet another quirk. I tried to log on to our VPN and the Cisco VPN client gave me me the following dialog box: “Error 51: Unable to communicate with the VPN subsystem. Please make sure that you have at least one network interface that is currently active and has an IP address and start this application again.”  Umm.
I popped over to the Cisco site and tried to see if maybe there was a 10.6 update for the client, but it turns out you have to have an account with them. After doing some more searching somebody suggested reinstalling the VPN client, so I tried it, and it works!
Cliffs: Reinstall the Cisco VPN client OR you can use Snow Leopard’s built int VPN client (more on this later)

After upgrading to Snow Leopard 10.6 I’ve run into yet another quirk. I tried to log on to our VPN and the Cisco VPN client gave me me the following dialog box: “Error 51: Unable to communicate with the VPN subsystem. Please make sure that you have at least one network interface that is currently active and has an IP address and start this application again.”  Umm.

vpn-fail

I popped over to the Cisco site and tried to see if maybe there was a 10.6 update for the client, but it turns out you have to have an account with them. After doing some more searching somebody suggested reinstalling the VPN client, so I tried it, and it works!

Cliffs: Reinstall the Cisco VPN client OR you can use Snow Leopard’s built int VPN client (more on this later)


12
Sep 09

Another vid of the widebody progress

Just a quick update of the widebody progress.


18
Jul 09

STaSIS/Alcon brake systems

My brake system upgrade arrived at Achtuning today. I choose to go with the STaSIS/Alcon 370mm (14.5″) 6 piston front kit and the 305mm (13.0″) rear rotor upgrade. The kit includes rotors, pads, Motul 5.1 fluid and Goodridge stainless steel lines, and necessary hardware.

I took the time to weigh the new brake system components:

Front carrier – 1.4lbs
Rear carrier – 0.6lbs

Front Alcon rotors 14.5″ – 14.5lbs
B6 S4 OEM 12.25″ –  26lbs

Rear Alcon rotors 13.0″ -13.3lbs
OEM 10.0″ – 9.4lbs

Front Alcon 6 piston calipers: 7.8lbs


08
Apr 09

Watermarking images paperclip’s post-processor

For those of you who wanted to use thoughtbot’s paperclip plugin to manage image uploads but were having trouble watermarking said images, behold!

http://github.com/ng/paperclip-watermarking-app/tree/master


14
Mar 09

Dynamically set a domain for a Rails asset host

I’ve been wanting to implement an asset host for my Rails app, looking over the API I saw that Rails’ asset_host only supported a single domain. I’m running multiple domains off one Rails app, so this would have been a problem. After a little research, I came up with a solution that would work for me.

I run this as a before_filter in my Application Controller.

# for my use, @site.domain returns the user's current
# domain. you should change this to whatever method
# you use to get the domain

class ApplicationController < ActionController::Base
before_filter :find_asset_host
 
private

  def find_asset_host
    ActionController::Base.asset_host = Proc.new { |source|
        asset_hosts = %w{icarus zeus aphrodite etc etc}
     
        # disable asset host for development
        if is_development?
          ""
        else
          "http://#{asset_hosts[rand(4)]}.#{@site.domain}"
        end
      }    
  end
 
end

06
Mar 09

Simple non-model check box properties

Need to pass a property that isn’t associated with a model? I did. It took me a few minutes, but the solution is codetty easy.

Instead of passing the instance variable your form is using, try this.

<% form_for [:admin, @post]} do |f| %>
  <%= f.error_messages %>
 
  <p>
    <%= f.label :title %>
    <%= f.text_field :title %>
  </p>

  <p>
    <%= label(:skip_queue, "Skip queue") %>
    <%= check_box("overrides", "skip_queue") %>
  </p>

  <p>
    <%= f.submit "Submit" %>
  </p>
<% end %>

You’d access the property of the check box like so:

# log
Processing Admin::PostsController#create (for 127.0.0.1 at 2009-03-06 03:03:01) [POST]
  Parameters: {"commit"=>"Update", "post"=>{"title"=>"Title", "overrides"=>{"skip_queue"=>"1"}}

# access the property
params[:overrides][:skip_queue]