Skip to content

Instantly share code, notes, and snippets.

View timriley's full-sized avatar
🇺🇦
Standing with Ukraine

Tim Riley timriley

🇺🇦
Standing with Ukraine
View GitHub Profile
alias dewip="sed -E -i '' -e '/^[[:blank:]]*@wip$/d;s/,[[:blank:]]*@wip//g;s/@wip,[[:blank:]]*//g' features/**/*.feature"
require 'irb/completion'
require 'irb/ext/save-history'
require 'rubygems'
require 'wirble'
require 'pp'
ARGV.concat [ "--readline" ]
Wirble.init
Wirble.colorize
sudo port install ruby
sudo port install rb-rubygems
sudo port install mysql5-server
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
sudo -u mysql mysql_install_db5
/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h yomi.local password 'new-password'
cd /opt/local/bin && sudo ln -s mysql5 mysql
require 'pp'
class Object
def tap
yield self
self
end
def tapp
pp self
self
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
@timriley
timriley / .gitconfig
Created January 14, 2010 04:48 — forked from kneath/._what.md
[alias]
up = !sh -c 'git pull && git log --pretty=format:\"%Cred%ae %Creset- %C(yellow)%s %Creset(%ar)\" HEAD@{1}..'
not_found do
render_template_if_exists!
end
def render_template_if_exists!
name = File.basename(request.path)
Dir["#{Sinatra::Application.root}/views/#{name}.*"].each do |match|
@_format = File.extname(match).sub(/^./, '')
@_template = File.basename(match, File.extname(match))
end
helpers do
def mobile_request?
[ /AppleWebKit.*Mobile/, /Android.*AppleWebKit/ ].any? {|r| request.env['HTTP_USER_AGENT'] =~ r}
end
def mobile_file(name)
File.exist?("#{options.views}/#{name}#{@mobile}.haml") ? :"#{name}#{@mobile}" : name.to_sym
end
def partial(name)
haml mobile_file("_#{name}"), :layout => false
end

Is it just me, or is it crazy that directly saving a model created via #build or #new on a has_many :through relationship does not create a join model?

See the migrations.rb, models.rb & test_irb_session.txt files below for a concise example of the problem.

This kind of technique is used commonly on nested controllers, and it would work fine for a plain belongs_to or has_many associations. In fact, this behaviour would stop me from using any RESTful controller helpers, like resource_controller.

Is there are way to make it work? Or do I need to look for alternatives, like the below?

s = Subject.first

a = Article.new

coffee app/scripts/*.coffee -wc -o public/javascripts