Articles
patch ODBCColumn with alias_method_chain
Here’s a quick-fix if you’re using the ODBC Adapter for Active Record gem/plugin and are getting errors with rake db:migrate when your schema includes a sql server sql_variant.
Continue Reading…
Posted by Luke on Mar 28, 2008
rails-mssql-tools update(rev. 10)
maintenance update
rev. 10 committed with:
svn ci -m "check for missing routines path;
catch AR::StatementInvalid errors and send original error to STDOUT"
Posted by Luke on Mar 28, 2008
wrap partial rendering in javascript
What I need is the ability to seamlessly send the contents of a partial to the client using the convenience of RJS, but wrapped inside a hand-written javascript condition (if some element exists, then update an element with this partial).
# RJS template
page << "if ('some_element_exists') {// page.replace_html using a partial}"
Continue Reading…
Posted by Luke on Mar 16, 2008
1 Comment(s)
“Google maps, geocoding, and search-by-zip made easy”
Have a look at mapperly, my latest RoR project which mixes together several Rails plugins I’ve been wanting to try out.
Continue Reading…
Posted by Luke on Jan 04, 2008
“Connection is busy with results for another command” bugger
The constant struggle with db scripts in Rails migrations is side-stepping the “Connection is busy with results for another command” error when attempting to run a typical script. Here’s how I’m dealing with it using mssql 2005 and sqlcmd.
First, create config/mssql_migrate.yml as shown:
server: myserver\sqlexpress
database: customers
Continue Reading…
Posted by Luke on Jan 03, 2008
1 Comment(s)
release 2
ActiveRecord::Base#find conditions option has been aliased to allow for Rails naming conventions against camel-cased schemas.
== CHANGELOG
2007-12-19 - 0.0.2
- :conditions hash in ActiveRecord::Base#find is conventionalized
Ex. find(:all, :conditions => {:user_name => 'Sam', :last_name => 'Bo'})
now becomes "UserName = 'Sam' AND..."
Continue Reading…
Posted by Luke on Jan 02, 2008
migrations with mssql 2005
My latest plugin, rails-mssql-tools, is now on Google Code. The README file is a good start. The plugin is a very simple solution to the 2 biggest challenges my team faces when using mssql with Rails:
- migrating procs, views, and triggers and
- conventionalizing model object attribute names for legacy db’s, with typical Microsoft development camel-casing for column names.
The plugin resolves both in a highly simplistic fashion, with the former relying on minimal code and maximum directory structure convention, while the latter overrides method_missing on ActiveRecord’s Base class to employ ActiveSupport’s string extensions.
Continue Reading…
Posted by Luke on Oct 09, 2007
Here’s how I {finally} got mssql 2005 to play nicely with my rails app:
~side-stepping the win32ole db error cannot create new connection because in manual or distributed transaction mode ~
- install odbc-rails using the Manual method. the gem and plugin methods didn’t work out for me.
- i copied Christian Werner’s odbc binding to \lib\ruby\site_ruby\1.8\i386-msvcrt but i believe the Manual method install script adds them (odbc_utf8.so, odbc.so) if they don’t already exist. check for them after running install_odbc.rb. also, Ruby v186 one-click installer includes the odbc.so binary, and i’m using that one instead of Werner’s: so far, so good.
- create a system dsn. in Windows, go to Start | Admin Tools | Data Sources. i created separate dsn’s for test and dev environments.
- database.config looks something like:
Continue Reading…
Posted by Luke on Sep 05, 2007
1 Comment(s)
using check_box_tag with remote_function
...here's a Rails helper example of sending a checkbox click with Ajax.
# call remote function by change event.
# uses unobtrusive js instead of inline.
# parameters:
# <tt>dom_id</tt> is element id for checkbox
# <tt>remote_options</tt> are options to remote_function
# <tt>value</tt> is same as core check_box helper
# <tt>checked</tt> is same as core check_box helper
# <tt>options</tt> is same as core check_box helper
def check_box_tag_remote(dom_id, remote_options, value = '1', checked = false, options = {})
html = ''
options.merge!({:id => dom_id})
html << check_box_tag(dom_id, value, checked, options)
remote_options.merge!({:with => %("value=#{value}")})
remote_js = remote_function(remote_options)
html << javascript_tag(%Q{
Event.observe('#{dom_id}', 'change', function(evt) {
#{remote_js}
}
);
})
end
Continue Reading…
Posted by Luke on Aug 06, 2007
how far down does this thing go?
more Ruby goodness
I continue to be impressed by how deep you can dig into every single Ruby object, class, module and "you name it". There seems to be nothing unreachable in a Ruby program, and just when I think I've found the bottom, another worm hole comes into view. Here's an example based on reading in Programming Ruby, 2nd Edition
(the pick axe book) :
# create the class
irb(main):018:0> class Shovel
irb(main):019:1> public
irb(main):020:1> def dig_deep
irb(main):021:2> never = 4
irb(main):022:2> ends = 2
irb(main):023:2> local_variables
irb(main):024:2> end
irb(main):025:1> end
# call instance method
irb(main):026:0> shovel = Shovel.new
=> #<Shovel:0x2dd04d0>
irb(main):027:0> shovel.dig_deep
=> ["never", "ends"]
The output of local_variables unto itself isn't what surprises me. But the way Ruby lets you see anything, at any time... that it was built to allow seemingly unlimited introspection... that's what makes Ruby so much fun.
Posted by Luke on Jul 27, 2007