Fri Feb 01 17:39:00 UTC 2008
fast date values for fixtures
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
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
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
Wed Dec 05 18:15:00 UTC 2007
rails inserts heinous html sometimes
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
I've noticed lately that I reuse a lot of code between controllers, in some cases entire methods. What if you could do something likedef comment_posted
<%= render :controller_partial => 'common/blog_posted' %>
end
