Category Archives: Rails

Ruby on Rails

Rails STI resouce routes routing

After hours of Googling and an ill timed browser reload while typing this the first time, I finally happened upon RoR ticket 10454 which details the problem I am having with inferred routes and STI models. I modified it to supposedly support any level of model nesting. Seems to work now. I [...]

has_many :through and with_scope protected

If you were following the excellent has_many :through blog, you may find you can’t use with_scope in the methods defined on your association. Instead, just send :with_scope along.

has_many :active_campaigns, :through => :campaign_distributions do
def

ed2k helper with Ruby

Nothing fancy. It works.

#!/usr/bin/ruby1.8

# ed2k link helper for Opera

host = ‘10.10.1.1′

link = ARGV.first

require ‘net/telnet’
core = Net::Telnet::new(
‘Host’ => host,
‘Port’ => 4000
)

core.cmd(”dllink #{link}”)
core.cmd(’q')
core.close

piston saves!

I download a prerelease of the latest Engines earlier in the summer with piston. My tests were failing in strange and magical ways. I spent quite a bit of time trying different things, then finally resorted to a fresh Rails app that I slowly populated with relevant files. Quickly I discovered the [...]

dry model validations with class_eval

I find myself having to validate an email address in a couple of different models. I’ve had to refine the pattern a couple of times, but don’t always remember to do it in every place, which is silly anyway. Since I don’t feel the need to delve into a new validation, like a [...]

ActiveScaffold and Mongrel death in production

Oh, I have such love for plugins that copy files around in production. I especially love it when the Rails app doesn’t have permission to write to the filesystem — why would it in production? — and Mongrel simply goes away. Running Mongrel without backgrounding it with start-stop-daemon reveals the trickery in action.

** [...]

Flash Upload Progress for Rails with FancyUpload for mootools

There are a ton of possible upload progress solutions for Web applications that need them. I had been using the upload progress that came with Merb, but I had modify mup.js to make Ajax calls using mootools instead of Prototype. Ultimately the progress status wasn’t updating consistently, so I sought a pure mootools [...]

Embarq DSL weak value!

Never in my life have I been so thoroughly ecstatic with a telecom provider. (Of course the honeymoon is over. Embarq is highly unreliable for DSL. Worse service I have ever had thus far.) Last Wednesday I ordered service completely online using the Embarq Web site. It was straightforward and [...]

Rails Migrations and PostgreSQL COPY

I admit it. I am bad. I run raw SQL in my migrations. The dataset I am working with requires it of me. It must be punished. To aid in its punishment, I found a post explaining how to get at PostgreSQL’s COPY from within the Postgres Ruby driver.
For a [...]

querying latest revision fails?

Have you been experiencing the hurt of Capistrano failing?

* executing task deploy
* executing task update
** transaction: start
* executing task update_code
* querying latest revision…
svn: invalid option: –limit
Type ’svn help’ for usage.
*** [update_code] transaction: rollback
* [update_code] rolling back

Never fear. You actually need a more recent [...]

Deployment Magic with Capistrano

Programming with Ruby and developing Web apps with Rails is fun; Obviously so, or you wouldn’t be reading about deployment issues. Deployment can be challenging and especially so if you come from more of a development background than a systems administration background. Fortunately, I’m tacking this from the latter camp, so I am [...]

Rails Plugin: Asset Bundle

Tonight I have been finishing up a plugin heavily based upon Scott Becker’s AssetPackager based upon my own interpretations of Serving JavaScript Fast. Mostly, I changed the way packages were handled, inserting each revision into a versioned directory instead of altering the filename. Further, jsPacker.pl is now preferred over jsmin if it is [...]

Ajax Scaffold, a Perfect Case for Rails Engines

Finally, I found some time to install Ajax Scaffold plugin tonight. I did have to wait an hour while asking the perpetual question, Is rubyforge ever up? Eventually, it was, and installed the plugin I did.
After configuration, Ajax Scaffold immediately copied some files into my project directories, including public/javascript, public/images, and apps/views. [...]

Fixes for acts_as_wizard plugin

Before I could start using acts_as_wizard a few things had to be changed. First, core_extensions.rb defined,

class Symbol
def to_str
id2name
end
end

But its presence broke filtered_access plugin. The purpose of the above seemed identical to the existing Symbol#to_s, so I don’t know why it’s there. I commented it [...]

Perl to rewrite label to label_for

After quickly scaffolding, you may find you want to actually use portions of the generated form _form.rhtml. If you’re using technoweenie’s labeled_form_helper plugin, the following Perl will quickly convert each label element into something more suitable.

$ perl -i -pe “s#([^#g" \
app/views/test/_test_form.rhtml

Before and after.

Email
'Email') %>

And, if you don't care about adding your [...]