Using Locomotive as your default Ruby
Really handy if you use an easy Rails install via Locomotive, and want your default to be one of the bundles from that. Using Locomotive as your default Ruby
Hiding the Bootcamp partition
If you have a bootcamp partition, but don’t need frequent access to the partition, you may not want it showing up all time, cluttering up the Desktop/sidebar, and potentially letting other users accidentally mess up your Windows install. While Parallels is running it hides the Bootcamp partition (at least if you are running the Parallels from Bootcamp option), but the rest of the time….
You can prevent the partition from being mounted easily enough by editing your fstab file. Those of you used to a more traditional Unix/Linux may be shocked to not find a file at /etc/fstab in the first place. Go ahead and make one, ignoring the /etc/fstab.hd file. In your new fstab you can just put the instructions for the noauto windows partition – that will leave the rest handled as usual by OS X. The following are the contents of mine, for handling my FAT partition.
LABEL=WINDOWS none msdos rw,noauto
Freezing Edge Rails with svn
Like running Edge rails with an svn:externals in your vendors folder, but don’t feeling like always having to stop right in the middle of development to bring your code up to speed because you ran an svn update in your root, and the core team committed something that broke it? Just use the revision flag in your externals property.
rails -r6414 http://dev.rubyonrails.org/svn/rails/trunk
Now svn pedit to bring it up to whatever revision you want (or drop it all together to run at HEAD again).
Principle of MOST surprise - aka ruby hazing 101
I suspect that the ruby Illuminati are going to have me killed for revealing this, because it seems to be a little booby-trap of goodness that is part of the learning experience, but WTF?!
irb(main):001:0> nil.id == 4
(irb):2: warning: Object#id will be deprecated; use Object#object_id
=> true
What this means, of course, is don’t be sloppy and assign from object.id when object might be nil, with no check, or you’ll be in for a surprise. For example, you could end up assigning an object to an admin user, when it should have no user assigned.
Fix for Typo Scribbish theme v2 - aka disabling a submit button in IE 2
I looked into it a little more this morning, and came up with how to still get the submit button disabling, to avoid double-posts, without having to rework anything substantially.
<%= submit_tag 'Submit', :onclick => "$('commentform').onsubmit();this.disabled=true;Element.hide('preview');return false;"%>
You first call the form’s onsubmit, since IE won’t call it if you submit the form via JavaScript, then you prevent browsers that don’t cancel the form when you disable the submit button from double-submitting, by returning false at the end.
This should still work with javascript off, if you have the “Allow non-Ajax comments” setting turned on.
Comments not working in Typo Scribbish theme 5
<%= submit_tag 'Submit', :onclick => "this.disabled=true; Element.hide('preview');" %>
The “this.disable=true” disables the submit button before the form is submitted, so all that happens is the onclick. For now I am just taking that out of mine – I’ll look at a better fix later.
Debug failing test with assert_dom_equal
assert_dom_equal('foo', @response.body)
right before the failing tests and you’ll get the full response body for the test dumped to your console.
It’s useful for discovering things like the fact that you forgot the = in <%= yield %> in your test layout.
Delete an individual entry from Firefox's address bar 2
Ever get tired of the first result in your address bar dropdown for a given URL being a typo that goes to a 404? Well, you can delete just that entry, after all.
In Firefox, if you want to delete an individual entry from the History, just highlight it (either in the History sidebar or in the address bar drop-down) and press Shift+Delete.
from: downloadsquad
Testing plugins : Remember to require 'action_controller/test_process'
Before I could even get started on actually coding the second piece of the Typo plugin, I spent a lot of time wondering why I was getting the following error when trying to run my tests:
NameError: uninitialized constant ActionController::TestRequest
I kept looking at the the other plugin I’ve been working on which the tests run just fine on and scratching my head. It turns out in the working plugin I had stashed the “require ‘action_controller/test_process’” line in the testing controller I made, so I didn’t notice the difference. I’ll be moving that back for clarity tomorrow, but remember kids, if you are doing controller driven tests outside of Rails (like in a plugin) put in that line.
ActiveRecord Observers are a very handy thing for plugins
While developing the first piece of the typo-permalink-with-id plugin I spent a lot of time trying to get the module extend/include and module_eval stuff just right so that my code had everything it needed to not through an error when trying to add a after_create to the app code itself. After a bunch if google around I found exactly what I need in teh v2 Agile book. It wasn’t something plug-in specific, but it is a godsend to plugin writers: ActiveRecord:Observer.
Instead of trying to get your after/before code properly mixed into the app code, you can have it nice and cleanly attached via an Observer. All of a sudden my code became very simple.
module TypoPermalinkWithId
class ArticleObserver < ActiveRecord::Observer
observe Article
def after_create(article)
article.permalink = "#{article.id}-#{article.permalink}"
article.save
end
end
ArticleObserver.instance
end

Articles via rss or email