Fri Feb 01 17:39:00 UTC 2008

fast date values for fixtures

Posted in Rails at 05:39 PM by matt

one of my annoyances while porting to rails 2 … and edge has to do with fixtures. they’ve decided to use the rathole plugin . . . but alas i was using the fixture_references plugin, and it seems they do not play nicely together. however, one thing i have learned is that i can do this:

 3.weeks.ago.to_s(:db)
=> "2008-01-11 17:38:26" 
>> (Time.now + 3.weeks).to_s(:db)
=> "2008-02-22 17:38:42" 
>> 

Tue Jan 29 13:48:00 UTC 2008

unitialized constant PASSTHROUGH exception in rails 2

Posted in Rails at 01:48 PM by matt

You need to upgrade to ruby 1.8.6 . . .

Wed Jan 09 10:44:00 UTC 2008

hacking irb and console for ruby and rails

Posted in Rails at 10:44 AM by matt

Two things you need for your console. Imagine the following

./script/console
>> helper.users_path
"/users"
(then highlight and copy to clipboard the following code.)
>> pastie
(browser opens to a pastie URL of the code you just copied to the clipboard


I also recommend installing wirble so you can have history in your console as well. ( sudo gem install wirble )


To get these helpful commands going in your irb or console session just add the following to your ~/.irbrc file.


# load rubygems and wirble
require 'net/http'
require 'rubygems' rescue nil
require 'wirble'

# load wirble
Wirble.init
Wirble.colorize

def Object.method_added(method)
  return super(method) unless method == :helper
  (class<<self;self;end).send(:remove_method, :method_added)

  def helper(*helper_names)
    returning $helper_proxy ||= Object.new do |helper|
      helper_names.each { |h| helper.extend "#{h}_helper".classify.constantize }
    end
  end

  helper.instance_variable_set("@controller", ActionController::Integration::Session.new)

  def helper.method_missing(method, *args, &block)
    @controller.send(method, *args, &block) if @controller && method.to_s =~ /_path$|_url$/
  end

  helper :application rescue nil
end if ENV['RAILS_ENV']

def pastie
  url = URI.parse("http://pastie.caboo.se/pastes/create")
  parameters = {}
  IO.popen('pbpaste') do |clipboard|
    parameters["paste[body]"] = clipboard.read
  end
  parameters["paste_parser"] = "ruby"
  parameters["paste[authorization]"] = "burger"
  pastie_url = Net::HTTP.post_form(url, parameters).body.match(/href="([^\"]+)"/)[1]
  IO.popen('pbcopy', 'w+') do |clipboard|
    clipboard.write(pastie_url)
  end
  pastie_url
  system("open " + pastie_url)
end

Tue Dec 11 11:01:00 UTC 2007

testing your tests in rails

Posted at 11:01 AM by matt

actually modifies your tests to verify what you’re testing

Wed Dec 05 18:15:00 UTC 2007

rails inserts heinous html sometimes

Posted at 06:15 PM by matt

Using button_to in rails inserts unnecessary div tags into your html and i recommend using the following override code in your application helper.



  def button_to(value, link, options={})
    if not options.empty?
      return super(value, link, options)
    end
    return "<input type=\"button\" value=\"#{value}\" onclick=\"location.href='#{url_for(link)}'\"/>"
  end


That way you get clean return values like



<input value="Submit" onclick="http://yoururl.com" />

rather than getting:


<div> <form method="post" action="http://yoururl.com" class="button-to"><div><input type="submit" value="Publish it" /></div></form> </div>
However this doesn't solve the method post problem





Mon Dec 03 18:54:00 UTC 2007

Controller Partials in rails

Posted at 06:54 PM by matt

I've noticed lately that I reuse a lot of code between controllers, in some cases entire methods. What if you could do something like
def comment_posted
   <%= render :controller_partial => 'common/blog_posted' %>
end

Sat Aug 25 17:43:00 UTC 2007

Mac OS X USB guru

Posted at 05:43 PM by matt

I'm trying to connect our *new* USB keyboard to an OS X machine and I want to gather the raw input data from it. I've got USB Prober going, but it doesn't look like I can ascertain raw input from that program alone, and frankly, I need help. If anyone is interested in seeing our new keyboard, and helping out with the driver software I'd love to cut you in on the action. I have plenty to worry about besides driver software - including but not limited to: finding some investors/and or just selling the thing. Starting on the User facing application, and creating some marketing buzz around the new product. Would love to hear if anyone is interested in coming in on this for a percentage. contact me at matt@beautifulsimplethings.com . I can give you more details about the new keyboard.

Sat Apr 21 12:16:00 UTC 2007

Welcome to BST

Posted at 12:16 PM by matt

We are Beautiful Simple Things. We beautify, simplify, and innovate new consumer electronics. We make playing Games more fun, and working with computers a beautiful thing. Currently, we are in the process of prototyping our first product. Let's just say, it's a BeaST, and we are very excited.