<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1653847677909457999</id><updated>2011-07-07T17:58:41.695-07:00</updated><category term='PHP'/><category term='Ruby on Rails'/><category term='JavaScript'/><category term='SQL'/><category term='CSS'/><category term='Ruby'/><category term='MediaWiki'/><category term='ExtJS'/><title type='text'>:code =&gt; @channelaaron.com</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://code-channelaaron.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://code-channelaaron.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Aaron Reichman</name><uri>http://www.blogger.com/profile/06867003164319105605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://homepage.mac.com/areichman/images/aaron_bw.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1653847677909457999.post-2899327436382067845</id><published>2009-07-28T10:18:00.000-07:00</published><updated>2009-07-28T10:18:41.235-07:00</updated><title type='text'>Avoid ActiveRecord::RecordNotFound Errors</title><content type='html'>When querying a database for specific model IDs, Active Record normally returns an "ActiveRecord::RecordNotFound" error if the model ID you are searching for does not exist.  For instance, if you run the following command:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Post.find(1)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;and record #1 does not exist, you will get the Active Record error.  In some cases, however, it's actually desirable for Active Record to return nil for the result instead of producing this error.  In these cases, use the 'find_by_id' method instead of the 'find' method.  For instance, you could run this command instead:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Post.find_by_id(1)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;and you will simply get back an empty set.  This method can also be used inside of the 'will_paginate' helpers like so:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Post.paginate_by_id(1)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;and again you will end up with an empty page with zero results instead of the normal Active Record error.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1653847677909457999-2899327436382067845?l=code-channelaaron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-channelaaron.blogspot.com/feeds/2899327436382067845/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1653847677909457999&amp;postID=2899327436382067845' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/2899327436382067845'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/2899327436382067845'/><link rel='alternate' type='text/html' href='http://code-channelaaron.blogspot.com/2009/07/avoid-activerecordrecordnotfound-errors.html' title='Avoid ActiveRecord::RecordNotFound Errors'/><author><name>Aaron Reichman</name><uri>http://www.blogger.com/profile/06867003164319105605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://homepage.mac.com/areichman/images/aaron_bw.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1653847677909457999.post-8258724746423097820</id><published>2009-03-19T07:03:00.000-07:00</published><updated>2009-03-19T07:09:24.966-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby on Rails'/><title type='text'>Manually Accessing Sessions in Rails 2.3</title><content type='html'>Due to some limitations with the Google Earth browser plugin, I'm forced to manually access my Rails session to retrieve data that is used in a dynamic KML file.  Previously, in Rails 2.2, I did something like this to access my ActiveRecord-based session:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;CGI::Session::ActiveRecordStore::Session.find_by_session_id(id)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In Rails 2.3, this doesn't work any more and you are presented an error of the form:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;uninitialized constant CGI::Session&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;To fix this, I found &lt;a href="http://blog.solid1pxred.com/post/75071082/rails-2-3-uninitialized-constant-cgi-session"&gt;this post&lt;/a&gt;, which notes to use &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ActionController::Session.find_by_session_id(id)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;instead.  However, per the &lt;a href="http://api.rubyonrails.org/classes/ActionController/Session.html"&gt;Rails API docs&lt;/a&gt;, that only works for CookieStore, AbstractStore, and MemCacheStore.  If you are using ActiveRecord for your stores like I am, this syntax instead is:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ActiveRecord::SessionStore::Session.find_by_session_id(id)&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1653847677909457999-8258724746423097820?l=code-channelaaron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-channelaaron.blogspot.com/feeds/8258724746423097820/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1653847677909457999&amp;postID=8258724746423097820' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/8258724746423097820'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/8258724746423097820'/><link rel='alternate' type='text/html' href='http://code-channelaaron.blogspot.com/2009/03/manually-accessing-sessions-in-rails-23.html' title='Manually Accessing Sessions in Rails 2.3'/><author><name>Aaron Reichman</name><uri>http://www.blogger.com/profile/06867003164319105605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://homepage.mac.com/areichman/images/aaron_bw.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1653847677909457999.post-6492935734679256061</id><published>2009-02-19T07:41:00.000-08:00</published><updated>2009-02-19T08:05:33.045-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby on Rails'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><title type='text'>Include the Table Name In the Rails options_for_select  Form Helper</title><content type='html'>In a Rails application, I have an advanced search form that allows the user to select any column from the database to search on.  This is currently set up to use an HTML select element with all of the column names listed as option elements.&lt;br /&gt;&lt;br /&gt;To make my searching easier, I wanted to show just the name of the column in the option element but have it return the name of the parent table and the column name.  For instance, I wanted the HTML to look like the following:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;select&amp;gt;&lt;br /&gt;&amp;lt;option value="my_table.column_name"&amp;gt;Column name&amp;lt;/option&amp;gt;&lt;br /&gt;&amp;lt;/select&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The Rails API documentation shows many examples of using collection of objects from a model etc., but I couldn't find any examples using the column names from the model.  So, after many failed attempts, I finally managed to get this syntax to work:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;%= options_for_select(MyTable.column_names.collect {|col| [col, "my_table." + col]} %&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In this example, I grab the column names using the built-in Rails method, then pass that array of strings to Ruby's collect method.  The collect method accepts a block that allows me to create a new array where each element is itself an array.  In these smaller arrays, I insert the column name directly and a string with the table name added to the beginning.  The array created by the collect method is now of the proper format expected by the Rails options_for_select form helper.&lt;br /&gt;&lt;br /&gt;I didn't think it would be this difficult, but in the end, I think the single line of code is pretty clean and simple.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Update&lt;/span&gt;&lt;br /&gt;Well, I guess my idea wasn't that new and cool.  As soon, as I posted this, I found the same solution in the API docs after all.  I was just looking in the options_for_select section, not the select selection.  See:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M001592"&gt;http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M001592&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1653847677909457999-6492935734679256061?l=code-channelaaron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-channelaaron.blogspot.com/feeds/6492935734679256061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1653847677909457999&amp;postID=6492935734679256061' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/6492935734679256061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/6492935734679256061'/><link rel='alternate' type='text/html' href='http://code-channelaaron.blogspot.com/2009/02/include-table-name-in-rails.html' title='Include the Table Name In the Rails options_for_select  Form Helper'/><author><name>Aaron Reichman</name><uri>http://www.blogger.com/profile/06867003164319105605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://homepage.mac.com/areichman/images/aaron_bw.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1653847677909457999.post-5999547308285985780</id><published>2009-02-11T06:53:00.001-08:00</published><updated>2009-02-11T07:01:03.869-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby on Rails'/><category scheme='http://www.blogger.com/atom/ns#' term='Ruby'/><title type='text'>Ruby: Require All Files In A Directory</title><content type='html'>In my Rails app, I have an external program that I keep in my lib directory for offline processing.  Within that program are several ruby classes that I'd like to load at startup.  Rather than adding require statements for each one and running the risk of forgetting one, you can load the whole directory with the following line of code:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Dir.glob(File.join(File.dirname(__FILE__), 'images/*.rb')).each {|f| require f }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;where, in my case, I'm loading all of the *.rb files in my lib/images folder.  Now, I can add new files to that directory and they will automatically get loaded at during startup of my external program.&lt;br /&gt;&lt;br /&gt;See &lt;a href="http://davidsmalley.com/2007/7/3/ruby-require-everything-in-a-directory"&gt;this link&lt;/a&gt; for more information.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1653847677909457999-5999547308285985780?l=code-channelaaron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-channelaaron.blogspot.com/feeds/5999547308285985780/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1653847677909457999&amp;postID=5999547308285985780' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/5999547308285985780'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/5999547308285985780'/><link rel='alternate' type='text/html' href='http://code-channelaaron.blogspot.com/2009/02/ruby-require-all-files-in-directory.html' title='Ruby: Require All Files In A Directory'/><author><name>Aaron Reichman</name><uri>http://www.blogger.com/profile/06867003164319105605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://homepage.mac.com/areichman/images/aaron_bw.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1653847677909457999.post-1628557347424569873</id><published>2009-01-30T06:52:00.000-08:00</published><updated>2009-01-30T07:00:09.813-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby on Rails'/><title type='text'>Redirects for restful_authentication</title><content type='html'>My Rails app is not deployed at the root level of my server (e.g. http://myserver.com).  In order to be able to serve up multiple mongrel_clusters for multiple Rails apps, users must access the site at http://myserver.com/myapp/.&lt;br /&gt;&lt;br /&gt;This caused one unforeseen issue with the restful_authentication plugin.  After installing this plugin (or gem), a file named authenticated_system.rb is added to your app's lib directory. Inside that file is a method called 'redirect_back_or_default' that is used to redirect the user every time they perform a login or logout.  This method in turn is then called by your Sessions controller (again, added by restful_authentication).&lt;br /&gt;&lt;br /&gt;When I attempted to login or logout from my app, I was constantly redirected to the root level of our server instead of the root level of my app.  This is obviously not what I wanted, and instead would prefer that users get redirected to the root URL for my app.&lt;br /&gt;&lt;br /&gt;The 'redirect_back_or_default' method takes a default value as an input.  So, to fix this, you simply need to modify your sessions_controller.rb file to include the proper default for your application.  In my case, I replaced the '/' value that was included in the Sessions controller by default with the 'root_url' helper.  Now when users logout, they return to the homepage of my application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1653847677909457999-1628557347424569873?l=code-channelaaron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-channelaaron.blogspot.com/feeds/1628557347424569873/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1653847677909457999&amp;postID=1628557347424569873' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/1628557347424569873'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/1628557347424569873'/><link rel='alternate' type='text/html' href='http://code-channelaaron.blogspot.com/2009/01/redirects-for-restfulauthentication.html' title='Redirects for restful_authentication'/><author><name>Aaron Reichman</name><uri>http://www.blogger.com/profile/06867003164319105605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://homepage.mac.com/areichman/images/aaron_bw.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1653847677909457999.post-6780970867301211778</id><published>2009-01-13T10:33:00.000-08:00</published><updated>2009-01-13T10:57:53.400-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby on Rails'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL'/><title type='text'>Rails 2.2.2 + mySQL + Windows</title><content type='html'>Doing Rails development on Windows just plain sucks.  Here's another reason why.  Upon upgrading to Rails 2.2.2, I started getting mySQL errors.  For one, the Ruby-based mySQL gem is no longer included with Rails 2.2.2.  Secondly, the Windows mySQL gem is broken and doesn't install its help docs.  Here's what helped me get back up and running:&lt;br /&gt;&lt;br /&gt;1.  Install the Windows mysql gem (gem install mysql) with the --no-rdoc and --no-ri options.&lt;br /&gt;&lt;br /&gt;2.  Copy libmysql.dll from your mysql/bin installation to your ruby/bin installation.  No clue why.  Just do it.&lt;br /&gt;&lt;br /&gt;[&lt;a href="http://softwaredevelopmentinchicago.wordpress.com/2008/12/22/rails-222-introduce-new-mysql-problems-in-windows/"&gt;Reference&lt;/a&gt;]&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1653847677909457999-6780970867301211778?l=code-channelaaron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-channelaaron.blogspot.com/feeds/6780970867301211778/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1653847677909457999&amp;postID=6780970867301211778' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/6780970867301211778'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/6780970867301211778'/><link rel='alternate' type='text/html' href='http://code-channelaaron.blogspot.com/2009/01/rails-222-mysql-windows.html' title='Rails 2.2.2 + mySQL + Windows'/><author><name>Aaron Reichman</name><uri>http://www.blogger.com/profile/06867003164319105605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://homepage.mac.com/areichman/images/aaron_bw.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1653847677909457999.post-2956652839548709275</id><published>2009-01-13T08:14:00.000-08:00</published><updated>2009-01-13T08:18:37.749-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MediaWiki'/><category scheme='http://www.blogger.com/atom/ns#' term='PHP'/><title type='text'>Allow MediaWiki To Use ImageMagick 5.x</title><content type='html'>I was hoping to use ImageMagick with MediaWiki for image uploads and resizing.  Unfortunately, I only had ImageMagick version 5.x installed.  With this version, MediaWiki produces and error since it is trying to send the -thumbnail option to ImageMagick's convert function.&lt;br /&gt;&lt;br /&gt;In version 5.x of ImageMagick, -resize does basically the same thing (-thumbnail just strips the metadata from the image).  So, instead of upgrading to version 6.x of ImageMagick, a quicker solution was to add the following to my LocalSettings.php file:&lt;br /&gt;&lt;br /&gt;$wgCustomConvertCommand = "/usr/sfw/bin/convert -resize %wx%h %s %d"&lt;br /&gt;&lt;br /&gt;This line is documented in DefaultSettings.php and is meant for using another graphics library like GM.  But instead, I just added in the convert command for ImageMagick 5.x.  Note that this line would be added to LocalSettings.php in place of the $wgUseImageMagick and $wgImageMagickConvertCommand variables.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1653847677909457999-2956652839548709275?l=code-channelaaron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-channelaaron.blogspot.com/feeds/2956652839548709275/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1653847677909457999&amp;postID=2956652839548709275' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/2956652839548709275'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/2956652839548709275'/><link rel='alternate' type='text/html' href='http://code-channelaaron.blogspot.com/2009/01/allow-mediawiki-to-use-imagemagick-5x.html' title='Allow MediaWiki To Use ImageMagick 5.x'/><author><name>Aaron Reichman</name><uri>http://www.blogger.com/profile/06867003164319105605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://homepage.mac.com/areichman/images/aaron_bw.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1653847677909457999.post-6903169490412487426</id><published>2008-10-01T10:04:00.001-07:00</published><updated>2008-10-01T10:12:21.145-07:00</updated><title type='text'>Refreshing Your Google Search Appliance Layout</title><content type='html'>If you make a change to the XSLT of your Google Search Appliance, the changes don't take effect right away and instead will appear on the order of 15 minutes later.  For testing any CSS layouts or design changes, this delay sucks.  &lt;br /&gt;&lt;br /&gt;I found the solution on &lt;a href="http://groups.google.com/group/Google-Search-Appliance-Help/browse_thread/thread/a9d849bc655099b9"&gt;this user forum&lt;/a&gt;.  Just add "&amp;reload_proxy=1" to the list of HTTP GET params included in your query in the URL and you should be able to instantly view your updated XSLT/CSS layout.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1653847677909457999-6903169490412487426?l=code-channelaaron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-channelaaron.blogspot.com/feeds/6903169490412487426/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1653847677909457999&amp;postID=6903169490412487426' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/6903169490412487426'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/6903169490412487426'/><link rel='alternate' type='text/html' href='http://code-channelaaron.blogspot.com/2008/10/refreshing-your-google-search-appliance.html' title='Refreshing Your Google Search Appliance Layout'/><author><name>Aaron Reichman</name><uri>http://www.blogger.com/profile/06867003164319105605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://homepage.mac.com/areichman/images/aaron_bw.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1653847677909457999.post-7155190731355936286</id><published>2008-09-26T08:32:00.000-07:00</published><updated>2008-09-26T08:47:25.126-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby on Rails'/><category scheme='http://www.blogger.com/atom/ns#' term='SQL'/><title type='text'>Easy Rails Quoting to Protect Against SQL Injection</title><content type='html'>If you have simple queries that you are performing in Ruby on Rails, it's very easy to use Active Record's bind variable facility.  For instance, you can easy protect against SQL injection using a syntax like this:&lt;br /&gt;&lt;br /&gt;Person.find(:all, :conditions =&gt; ["name = ?", params[:name] ]&lt;br /&gt;&lt;br /&gt;However, when you start building up more complex SQL queries, using the simple Active Record finders don't always work.  Depending on the type of search you are performing, you can very quickly end up with a large number of search criteria and a very complex SQL statement, requiring use of the "find_by_sql" method instead.  So how do you protect against SQL injection in these complex cases?&lt;br /&gt;&lt;br /&gt;One way is to take advantage of the same quoting methods that the Active Record finders use.  There are several methods available and those can be reviewed in the &lt;a href="http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Quoting.html"&gt;Rails API documentation&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;To use these methods, use the following syntax:&lt;br /&gt;&lt;br /&gt;Person.connection.quote(params[:name])&lt;br /&gt;&lt;br /&gt;This will add quotes around your input string while escaping any existing single quotes or backslashes.  Then, you can pass your newly escaped string into your WHERE clause in "find_by_sql" or into a conditions variable that you can pass around.&lt;br /&gt;&lt;br /&gt;[Thanks to &lt;a href="http://misuse.org/science"&gt;Steve Midgley&lt;/a&gt; for pointing this out to me]&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1653847677909457999-7155190731355936286?l=code-channelaaron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-channelaaron.blogspot.com/feeds/7155190731355936286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1653847677909457999&amp;postID=7155190731355936286' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/7155190731355936286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/7155190731355936286'/><link rel='alternate' type='text/html' href='http://code-channelaaron.blogspot.com/2008/09/easy-rails-quoting-to-protect-agains.html' title='Easy Rails Quoting to Protect Against SQL Injection'/><author><name>Aaron Reichman</name><uri>http://www.blogger.com/profile/06867003164319105605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://homepage.mac.com/areichman/images/aaron_bw.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1653847677909457999.post-6819328183673176442</id><published>2008-07-16T10:07:00.000-07:00</published><updated>2008-07-16T10:23:26.324-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaScript'/><category scheme='http://www.blogger.com/atom/ns#' term='CSS'/><category scheme='http://www.blogger.com/atom/ns#' term='ExtJS'/><title type='text'>Re-Enable Text Selection From An ExtJS Grid</title><content type='html'>For some reason, an ExtJS GridPanel does not allow you to highlight or select any of the text that it renders.  This is extremely annoying when your Grid has some very long data strings that users may want to copy and paste between apps.  For example, you might want to copy an image filename or copy a long serial number from a Grid and paste it into Excel.  Well, you can't.&lt;br /&gt;&lt;br /&gt;The reason is that Ext is defining all of the divs that contain the data with an extra 'unselectable=on' field. To fix this, I followed &lt;a href="http://extjs.com/forum/showthread.php?t=22218"&gt;this post&lt;/a&gt; and everything seems to work.  I've tested this on both Firefox 2.0 and IE6.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt; IE fix, using JavaScript &gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;/**&lt;br /&gt; * http://extjs.com/forum/showthread.php?t=22218&lt;br /&gt; * For non-IE browsers, this is fixed with a CSS addition.&lt;br /&gt; * @param {Ext.grid.GridPanel} grid The GridPanel to fix.&lt;br /&gt; */&lt;br /&gt;var reenableTextSelection = function(grid){&lt;br /&gt;    if(Ext.isIE){&lt;br /&gt;    grid.store.on("load", function(){&lt;br /&gt;        var elems=Ext.DomQuery.select("div[unselectable=on]", grid.dom);&lt;br /&gt;        for(var i=0, len=elems.length; i&amp;lt;len; i++){&lt;br /&gt;            elems[i].unselectable = "off";&lt;br /&gt;        }&lt;br /&gt;    });&lt;br /&gt;    }&lt;br /&gt;};&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt; CSS fix for Firefox and Safari &gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;.x-grid3-row td,&lt;br /&gt;.x-grid3-summary-row td,&lt;br /&gt;.x-grid3-cell-text,&lt;br /&gt;.x-grid3-hd-text,&lt;br /&gt;.x-grid3-hd,&lt;br /&gt;.x-grid3-row {&lt;br /&gt; -moz-user-select:inherit;&lt;br /&gt; -khtml-user-select:text;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Make sure that your CSS stylesheet is loaded &lt;span style="font-weight:bold;"&gt;after&lt;/span&gt; the Ext stylesheet is loaded.  Otherwise these overrides for Firefox and Safari won't be accessed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1653847677909457999-6819328183673176442?l=code-channelaaron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-channelaaron.blogspot.com/feeds/6819328183673176442/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1653847677909457999&amp;postID=6819328183673176442' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/6819328183673176442'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/6819328183673176442'/><link rel='alternate' type='text/html' href='http://code-channelaaron.blogspot.com/2008/07/re-enable-text-selection-from-extjs.html' title='Re-Enable Text Selection From An ExtJS Grid'/><author><name>Aaron Reichman</name><uri>http://www.blogger.com/profile/06867003164319105605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://homepage.mac.com/areichman/images/aaron_bw.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1653847677909457999.post-2657165275424861462</id><published>2008-06-12T11:13:00.000-07:00</published><updated>2008-09-26T08:43:56.513-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby on Rails'/><title type='text'>Add GET Parameter Options to paginating_find</title><content type='html'>I'm using the &lt;a href="http://cardboardrocket.com/pages/paginating_find"&gt;paginating_find plugin&lt;/a&gt; for my Rails app and I really wanted to add additional HTTP GET parameters to the page links that are created.  Normally, when you include the pagination helper like this:&lt;br /&gt;&lt;br /&gt;&lt;%= paginating_links(@images) %&gt;&lt;br /&gt;&lt;br /&gt;you get the following URL: http://my.app.com/action?page=1&lt;br /&gt;&lt;br /&gt;But I wanted this:  http://my.app.com/action?page=1&amp;view=detail&lt;br /&gt;&lt;br /&gt;After poking around in the code, I noticed that the helper accepted a params hash (it just passes this to the default Rails link_to method), but I didn't know what format to use in the helper.  So, after some trial and error with added puts statements (remember, if you change the plugin code, you need to restart WEBrick), this syntax ultimately worked:&lt;br /&gt;&lt;br /&gt;&lt;%= paginating_links(@images, options = {:params =&gt; {:view =&gt; @view}}) %&gt;&lt;br /&gt;&lt;br /&gt;where @images is the instance variable containing the objects to be paginated and @view is the instance variable containing a string that I want passed in the URL for the GET parameter called 'view'.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1653847677909457999-2657165275424861462?l=code-channelaaron.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-channelaaron.blogspot.com/feeds/2657165275424861462/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1653847677909457999&amp;postID=2657165275424861462' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/2657165275424861462'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1653847677909457999/posts/default/2657165275424861462'/><link rel='alternate' type='text/html' href='http://code-channelaaron.blogspot.com/2008/06/add-get-paremeter-options-to.html' title='Add GET Parameter Options to paginating_find'/><author><name>Aaron Reichman</name><uri>http://www.blogger.com/profile/06867003164319105605</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://homepage.mac.com/areichman/images/aaron_bw.jpg'/></author><thr:total>0</thr:total></entry></feed>
