Fri Oct 03 12:13:00 UTC 2008

rexml/formatters/pretty.rb:131:in `wrap': stack level too deep (SystemStackError)

Posted in Rails at 12:13 PM by matt

Getting rexml/formatters/pretty.rb:131:in `wrap': stack level too deep (SystemStackError) ? I recommend monkey patching that file with the following basically, find the two methods below, and add what you don't see in the source file.
def initialize( indentation=2, ie_hack=false )
        @indentation = indentation
        @level = 0
        @ie_hack = ie_hack
        @width = 80
        @stack_level = 0
end

def wrap(string, width)
  # Recursively wrap string at width.
  @stack_level = @stack_level + 1
  if @stack_level >= 1200
    return string + '...'
  end
  return string if string.length <= width
  place = string.rindex(' ', width) # Position in string with last ' ' before cutoff
  if place
    return string[0,place] + "\n" + wrap(string[place+1..-1], width)
  else
    return string # cannot wrap
  end
end

Wed Sep 17 11:38:00 UTC 2008

flickr scaling guru cal henderson talks django and rails

Posted in Geeking it up, Rails at 11:38 AM by matt

this is a hilarious talk that flickr scaling guru cal henderson gave on the current state of the art with frameworks and what they are lacking. Mr. Henderson has some great comments on what is lacking with the current popular frameworks. Also, I haven't seen someone this funny give a talk in a long time. He should do standup comedy... enjoy

Fri Sep 12 14:51:00 UTC 2008

more on testing your tests with rcov

Posted in Rails at 02:51 PM by matt

If you ever wondered how good your testing is doing I highly recommend seeing how much coverage your tests are fulfilling. You can do this by running rcov. It will run your tests and figure out which parts of your code are being run when you run your tests. Its pretty simple you just run
sudo gem install rcov
#then from your RAILS_ROOT path
rcov -o /path/to/output/results test/unit/*_test.rb test/functional/*/*_test.rb
and you will end up getting results that SHOW things like so:
C0 code coverage information
Uploaded with plasq's Skitch!
the teal color shows the code thats covered, the red, the code that is not covered by your tests. prett slick huh?
app/controllers/user/home_controller.rb - C0 code coverage information
Uploaded with plasq's Skitch!

Mon May 19 17:01:00 UTC 2008

script to find and replace a string in all files and subdirectories using shell programming

Posted in Rails at 05:01 PM by matt

#!/bin/sh

if [ $# -ne 2 ]; then
        echo 1>&2 Usage: $0 [string to replace] [replacement]
        exit 127
fi

for file in $(find . -type f | grep -v .svn | grep -v .jpg | grep -v .gif | grep -v .tmp | grep -v .zip 
| grep -v .png | grep -v .ttf | grep -v .psd | grep -v tempfile.tmp)
do
        sed -e "s/$1/$2/g" $file > /tmp/tempfile.tmp
        mv /tmp/tempfile.tmp $file
done
for file in $(find . | grep -v .svn | grep tempfile.tmp)
do
        rm $file
done

Tue Feb 19 20:01:00 UTC 2008

selenium on rails

Posted in Rails at 08:01 PM by matt

For rails 2 i was having problems getting selenium going. the upper left corner of my page was missing the layout. e.g.
ActionController::MissingTemplate layout




change the file /vendor/plugins/selenium_on_rails/lib/controllers/selenium_controller.rb on line 22
to use layout => false

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.)<br/>
>> pastie
#(browser opens to a pastie URL of the code you just copied to the clipboard<br/>

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

Fri Jan 04 15:11:00 UTC 2008

Paypal SDK zip For Rails

Posted in Rails at 03:11 PM by matt

the paypal rails SDK for Rails

It took me forever to find the software development kit for Paypal express checkout and rails. The downloads on this page have rails apps for most everything you could imagine doing with paypal and rails. hope this saves you some time looking for the link.

Wed Dec 12 11:16:00 UTC 2007

skitch for ruby developers

Posted in Rails at 11:16 AM by matt

If you are developer using ruby a lot, or rails a lot, and find yourself in the irb console all the time, or trading code with other developers a lot I highly recommend utility belt .

I can type lines of code
>>def say_hi
>>  puts 'hi'  #note it autoindents for me here too
>>end

#Copy that code, and then just type

>>pst

and then my browser opens up into a beautiful pastie url

If you are a designer and don’t have Skitch yet then you are missing out.

Mon Oct 15 04:02:00 UTC 2007

assert_hangs

Posted in Rails at 04:02 AM by matt

another thing that rails needs for testing transactions and how large your alpha geek ego is:

assert_hung @me.hung_like_horse

....

but seriously.

how do you know that code such as

def some_controller
  @profile.save

  @user.profile = @profile

  @user.save
end
is all being done without interruption from some process like FERRET dying without an error?? what if you could do…
hangs_after(profile_save)
assert_hung_after(profile_save)
or something of the sort to test the atomicity of your controller ?
def some_controller
  transaction.do   
    @profile.save

    @user.profile = @profile

    @user.save
  end
end

Thu Sep 06 12:39:00 UTC 2007

testing your restful routes

Posted in Rails at 12:39 PM by matt

script/console
>> irb ActionController::Routing::Routes
rs = ActionController::Routing::Routes
rs.named_routes.each {|name, route| puts( name, route) }; 1
Just copy the list of helper methods show in the output of step 4 and append path to that name. You must also provide the required ids shown in the output. For example take the output:
#user
#GET /users/:id/ {:action=>"show", :controller=>"users"}

#and in the console, type:
>> user_path 1
=> "/users/1"
The same process can be used for nested routes.

Reference: Rails Routing by David A Black. This book gave me a solid understanding of routes.

-taken from blog spot

Thu Aug 30 12:28:00 UTC 2007

ruby sql query syntax

Posted in Rails at 12:28 PM by matt

Perusing some useful blogs – love err the blog. Thought I’d share the link. Another form of rails sql syntax

Mon Aug 13 14:36:00 UTC 2007

what ruby on rails needs

Posted in Rails at 02:36 PM by matt

in one line what rails doesn’t have but needs

render :action => 'index', :anchor => 'signup'

Thu Aug 02 17:41:00 UTC 2007

Moving an older version of source to the head

Posted in Rails at 05:41 PM by matt

This article is a minor reminder of what needs to happen in order to make an older version of source code in subversion come back (to be restored) to the head.

mkdir svntest

        vi svntest/afile.rb

add the line version 1 exit

svn add svntest 
        svn ci -m "added version 1"

        vi svntest/afile.rb

add the line

    version 2

exit and then run

svn ci -m "added version 2"
now to merge back version 1 to head

if i try to do

svn merge -rhead:1471 http://svn.domain.com/svntest

then i get

    Skipped missing target: &#8216;afile.rb&#8217;

but if do

cd svntest
        svn merge -rhead:1471 http://svn.domain.com/svntest

i get

    U afile.rb

sweet, lets check it in.

svn ci -m "changed to version 1"

i get

    Sending        svntest/afile.rb
    Transmitting file data .
    Committed revision 3.

    cat afile.rb
    version 1

yay!!