<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>OffAxis</title>
    <description>A skewed take on the consulting business.</description>
    <link>http://conceptsahead.com/off-axis/</link>
    <item>
      <title>Seed Migrations for Ruby on Rails</title>
      <description>&lt;p&gt;&lt;a href=&quot;http://github.com/n3bulous/seed_migrations&quot;&gt;Seed Migrations&lt;/a&gt; provides migration-like support for seed data.  Ruby on Rails versions 3 and 2.3.4 introduced the &lt;strong&gt;db:seed&lt;/strong&gt; Rake task that executes a &lt;em&gt;db/seeds.rb&lt;/em&gt; file containing normal ruby code.  There's nothing special about the code that goes in this file, and no other special features for managing seed data are provided.  Depending on how you write your code, running &lt;strong&gt;rake db:seed&lt;/strong&gt; multiple times yields duplicate data inserts.&lt;/p&gt;

&lt;p&gt;The main features provided:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a seedings table in your database to track which seeds have been previously loaded&lt;/li&gt;
&lt;li&gt;support for Rails versions before 2.3.4 which lack the &lt;strong&gt;db:seed&lt;/strong&gt; Rake task&lt;/li&gt;
&lt;li&gt;&lt;em&gt;db/seeds/seed_order.yaml&lt;/em&gt; controls the seed load order&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;script/generate seed&lt;/strong&gt; &lt;strong&gt;&lt;em&gt;descriptive-name&lt;/em&gt;&lt;/strong&gt;&lt;/em&gt; generates an empty, timestamped seed file and appends an appropriate entry to &lt;em&gt;db/seeds/seed_order.yaml&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Installation is simply:&lt;/p&gt;

&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;  script/plugin git://github.com/n3bulous/seed_migrations.git
  cp vendor/plugins/n3bulous-seed_migrations/db/seeds.rb db/&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;</description>
      <pubDate>Tue, 03 Nov 2009 16:21:46 +0000</pubDate>
      <link>http://conceptsahead.com/off-axis/seed-migrations-for-ruby-on-rails</link>
      <guid>http://conceptsahead.com/off-axis/seed-migrations-for-ruby-on-rails</guid>
    </item>
    <item>
      <title>ASCIIcasts Summary #178: Seven Rails Security Tips</title>
      <description>&lt;p&gt;&lt;a href=&quot;http://asciicasts.com&quot;&gt;ASCIIcasts&lt;/a&gt; rock.  There's a place for screencasts and video demonstrations, but conveying something like the points in &lt;a href=&quot;http://railscasts.com/episodes/178-seven-security-tips&quot;&gt;Seven Security Tips&lt;/a&gt; isn't one of them.  The only thing better is just giving a summary, so here it goes.&lt;/p&gt;

&lt;h2&gt;1. Use attr_accessible in your model to avoid side effects with mass assignment.&lt;/h2&gt;

&lt;p&gt;When assigning object values with something like &lt;code&gt;User.new(params[:user])&lt;/code&gt; or &lt;code&gt;update_attributes(params[:user])&lt;/code&gt;, unintended fields, like allow_admin or has_many relations, may be set with a tool like &lt;code&gt;curl&lt;/code&gt;.  To prevent this, use &lt;code&gt;attr_accessible&lt;/code&gt;  in the model to whitelist the fields mass assignment may use.&lt;/p&gt;

&lt;h2&gt;2. Use &lt;code&gt;validates_attachment_content_type&lt;/code&gt; to whitelist upload content types.&lt;/h2&gt;

&lt;p&gt;You do not want users to upload PHP scripts and whatnot to an accessible portion of your site.&lt;/p&gt;

&lt;h2&gt;3. Enable &lt;code&gt;filter_parameter_logging&lt;/code&gt; for fields that should not be saved in the log files.&lt;/h2&gt;

&lt;p&gt;It's bad enough when developers fail to encrypt passwords in a database.  The next worse blunder is logging the unencrypted passwords.  Use this in your &lt;em&gt;application_controller.rb&lt;/em&gt; to filter occurrences of parameters.  See the &lt;a href=&quot;http://api.rubyonrails.org/classes/ActionController/Base.html#M000647&quot;&gt;Rails API entry&lt;/a&gt; for more info.  API summary: the filter operates on case-insensitive substrings of all parameters defined.&lt;/p&gt;

&lt;h2&gt;4. Protect against CSRF by adding &lt;code&gt;protect_from_forgery&lt;/code&gt; to your ApplicationController.&lt;/h2&gt;

&lt;p&gt;Simple yet effective.&lt;/p&gt;

&lt;h2&gt;5. Scope your Active Record finds to the current user.&lt;/h2&gt;

&lt;p&gt;This is an easy one to overlook.  The first trick is making sure your &lt;a href=&quot;http://guides.rubyonrails.org/association_basics.html&quot;&gt;relationships&lt;/a&gt; are defined in your models.  Once they are in place you can leverage the association magic: &lt;code&gt;current_user.orders.find(params[:id])&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;6. Fer cryin' out loud, parameterize your SQL already!&lt;/h2&gt;

&lt;p&gt;This should be self-explanatory.  In fact, it shouldn't even need mentioning.  OK, here's a snippet stolen from the ASCIIcast which borrowed from the Railscast:&lt;/p&gt;

&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span style=&quot;color:#33B&quot;&gt;@projects&lt;/span&gt; = current_user.projects.all(
    &lt;span style=&quot;color:#A60&quot;&gt;:conditions&lt;/span&gt; =&amp;gt; [&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;name like ?&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;background: #eee&quot;&gt;&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;#{&lt;/span&gt;params[&lt;span style=&quot;color:#A60&quot;&gt;:search&lt;/span&gt;]&lt;span style=&quot;font-weight: bold; color: #888&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;])&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;7. Sanitize user provided values when displaying HTML.&lt;/h2&gt;

&lt;p&gt;The Railscast instructs you to use the &lt;code&gt;h&lt;/code&gt; method (e.g. &lt;code&gt;&amp;lt;%= h comment.naughty_value =&amp;gt;&lt;/code&gt;), but since Rails 3 will do this automatically, you might be better off using &lt;a href=&quot;http://code.google.com/p/xssterminate/&quot;&gt;xss_terminate&lt;/a&gt; which is a handy &quot;install and forget&quot; plugin.&lt;/p&gt;</description>
      <pubDate>Sun, 13 Sep 2009 04:24:16 +0000</pubDate>
      <link>http://conceptsahead.com/off-axis/asciicasts-summary-178-seven-rails-security-tips</link>
      <guid>http://conceptsahead.com/off-axis/asciicasts-summary-178-seven-rails-security-tips</guid>
    </item>
    <item>
      <title>ActiveScaffold and FCKeditor</title>
      <description>&lt;p&gt;To paraphrase a common saying, &quot;open source software is only free if your time has no value.&quot;  Such was the last day of work while trying to integrate &lt;a href=&quot;http://www.activescaffold.com/&quot;&gt;ActiveScaffold&lt;/a&gt; and &lt;a href=&quot;http://ckeditor.com/blog/FCKeditor_2.6.4_released&quot;&gt;FCKeditor&lt;/a&gt;.  The sad thing is that it really shouldn't have been this way.&lt;/p&gt;

&lt;p&gt;For starters, people really need to update their project's documentation (see most of the README files on github).  Secondly, the documentation should include a somewhat logical example.  Each code snippet should meaningfully pertain to the other, related code snippets.  Thirdly, the example code should actually work.  Fourthly, the previous three rules go doubly if you are dealing with JavaScript.&lt;/p&gt;

&lt;p&gt;OK, I'm finished venting.  Let's get to the meat and potatoes.  I'm assuming you have a model working with ActiveScaffold, which is generally pretty simple to get up and running.&lt;/p&gt;

&lt;p&gt;The two primary resources for installing were the (a) github page for the &lt;a href=&quot;http://github.com/davividal/fckeditor/tree/master&quot;&gt;github fckeditor plugin&lt;/a&gt; and the most useful, but slightly incomplete, &lt;a href=&quot;http://ganeshmohan.wordpress.com/2008/11/12/fck-editor-plugin-in-activescaffold/&quot;&gt;FCK Editor Plugin in ActiveScaffold&lt;/a&gt;.  Without further commentary, here are the steps, minus the premature balding inducing frustration.&lt;/p&gt;

&lt;p&gt;Install the FCKeditor plugin from within your Rails application:&lt;/p&gt;

&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;script/plugin install git&lt;span style=&quot;color:#A60&quot;&gt;:/&lt;/span&gt;/github.com/davividal/fckeditor.git
rake fckeditor&lt;span style=&quot;color:#A60&quot;&gt;:install&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;The following steps relate to a simple admin controller for an equally simple About model.&lt;/p&gt;

&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;script/generate model about content:text published:boolean
rake db:migrate
mkdir app/controllers/admin
mkdir app/helpers/admin/
mkdir -p app/views/admin/about
touch app/controllers/admin/about_controller.rb
touch app/helpers/admin/about_helper.rb
touch app/views/layouts/admin.html.erb
cp vendor/plugins/active_scaffold/frontends/default/views/_create_form.html.erb app/views/admin/about/
cp vendor/plugins/active_scaffold/frontends/default/views/_update_form.html.erb app/views/admin/about/&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;The Admin::About controller:&lt;/p&gt;

&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;Admin::AboutController&lt;/span&gt; &amp;lt; &lt;span style=&quot;color:#036; font-weight:bold&quot;&gt;ApplicationController&lt;/span&gt;
  layout &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;admin&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;
  active_scaffold &lt;span style=&quot;color:#A60&quot;&gt;:about&lt;/span&gt;
&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;The following lines need to be included in your admin layout:&lt;/p&gt;

&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;&amp;lt;&lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;%=&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt; javascript_include_tag :defaults, &amp;quot;builder&amp;quot;, &amp;quot;scriptaculous&amp;quot;, &amp;quot;fckeditor/fckeditor&amp;quot; %&amp;gt;
&amp;lt;%&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;=&lt;/span&gt;&lt;/span&gt; active_scaffold_includes &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Here's the about helper:&lt;/p&gt;

&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;module&lt;/span&gt; &lt;span style=&quot;color:#B06; font-weight:bold&quot;&gt;Admin::AboutHelper&lt;/span&gt;
  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;content_form_column&lt;/span&gt;(record, input_name)
    fckeditor_textarea(&lt;span style=&quot;color:#A60&quot;&gt;:record&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:content&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:ajax&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color:#038; font-weight:bold&quot;&gt;true&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:width&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;800px&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:height&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;200px&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)
  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;

  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color:#06B; font-weight:bold&quot;&gt;content_column&lt;/span&gt;(record)
    sanitize(record.content)
  &lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;
&lt;span style=&quot;color:#080; font-weight:bold&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;In the two admin/about partials, you need to replace submit button code with the following:&lt;/p&gt;

&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span style=&quot;color:#800; font-weight:bold&quot;&gt;&amp;amp;lt;&lt;/span&gt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Update&amp;quot; class=&amp;quot;submit&amp;quot;
       onClick=&amp;quot;var oEditor = FCKeditorAPI.GetInstance('record_&lt;span style=&quot;color:#888&quot;&gt;&amp;lt;%=@record.id%&amp;gt;&lt;/span&gt;_&lt;span style=&quot;color:#888&quot;&gt;&amp;lt;%='content'%&amp;gt;&lt;/span&gt;_editor');
       $('record_&lt;span style=&quot;color:#888&quot;&gt;&amp;lt;%=@record.id%&amp;gt;&lt;/span&gt;_&lt;span style=&quot;color:#888&quot;&gt;&amp;lt;%='content' %&amp;gt;&lt;/span&gt;_editor_hidden').value = oEditor.GetXHTML();&amp;quot; /&lt;span style=&quot;color:#800; font-weight:bold&quot;&gt;&amp;amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Substitute Update for Create as appropriate.  This last bit is very important, and not mentioned pretty much anywhere except Ganesh's post.  You'll notice one important difference from his code though: when assigning the hidden variable you need to actually add the &quot;_hidden&quot; part to the id.&lt;/p&gt;

&lt;p&gt;Hopefully this helps someone roll with FCKeditor and ActiveScaffold (or Ajax in general) without wasting their Labor Day Sunday as I did.  Let me know if something doesn't work.  I know that input statement needs real angle brackets, but I'm too tired to debug that display issue just this minute.&lt;/p&gt;

&lt;p&gt;UPDATE: Since all my new projects use jQuery, I'll be switching to this &lt;a href=&quot;http://code.google.com/p/jwysiwyg/&quot;&gt;jQuery.wysiwyg&lt;/a&gt;.&lt;/p&gt;</description>
      <pubDate>Mon, 07 Sep 2009 04:24:25 +0000</pubDate>
      <link>http://conceptsahead.com/off-axis/activescaffold-and-fckeditor</link>
      <guid>http://conceptsahead.com/off-axis/activescaffold-and-fckeditor</guid>
    </item>
    <item>
      <title>Identically Named Methods in a Rails Controller</title>
      <description>&lt;p&gt;First off, never do this.  Of course, you wouldn't.  Except by accident.  I'm only admitting to it in the hopes someone else out there doesn't waste too much time with something so simple.&lt;/p&gt;

&lt;p&gt;I was RESTifying a controller by whitelisting methods and then testing.  For #show I forgot to delete the private version before testing.  Hilarity ensued.  Neither Mongrel or Thin would tell me there was a problem, but, even though I had a show method, I was told it didn't exist.  On a whim, I scrolled to the bottom of the file and noticed that show existed as a private method, and removing it promptly solved my problem.&lt;/p&gt;

&lt;p&gt;While playing with routes to figure out the problem, I also encountered #show rendering show.rhtml, (it's old code) -- the server appeared to be running the private method instead of the public version.  This is probably a bug, but in Ruby or Rails?&lt;/p&gt;</description>
      <pubDate>Tue, 26 May 2009 18:17:07 +0000</pubDate>
      <link>http://conceptsahead.com/off-axis/identically-named-methods-in-a-rails-controller</link>
      <guid>http://conceptsahead.com/off-axis/identically-named-methods-in-a-rails-controller</guid>
    </item>
    <item>
      <title>Careful with that config.gem, Eugene</title>
      <description>&lt;p&gt;With the advent of &lt;a href=&quot;http://github.com&quot;&gt;Github&lt;/a&gt; as the Ruby Gem hosting platform of choice, you have to be specific when you use config.gem in you &lt;em&gt;config/environment.rb&lt;/em&gt; file.&lt;/p&gt;

&lt;p&gt;Recently, I noticed that my Rails application generated from a  &lt;a href=&quot;http://www.youvegotrails.com/&quot;&gt;You've Got Rails&lt;/a&gt; template was choking on the rubyist-aasm library.  Given the following configuration in &lt;em&gt;config/environment.rb&lt;/em&gt;:&lt;/p&gt;

&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;  config.gem &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;rubyist-aasm&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Which would yield the following errors initially discovered when running Rake:&lt;/p&gt;

&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;  no such file to load -- rubyist-aasm
  ...
  Missing these required gems:
    rubyist-aasm&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;The problem appears due to Github namespacing gems by prefixing the username to the Gem name.  The solution is to specify the actual library name:&lt;/p&gt;

&lt;div class=&quot;CodeRay&quot;&gt;
  &lt;div class=&quot;code&quot;&gt;&lt;pre&gt;  config.gem &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;rubyist-aasm&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:lib&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;aasm&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;color:#A60&quot;&gt;:source&lt;/span&gt; =&amp;gt; &lt;span style=&quot;background-color:#fff0f0&quot;&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color:#D20&quot;&gt;http://gems.github.com&lt;/span&gt;&lt;span style=&quot;color:#710&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;</description>
      <pubDate>Fri, 10 Apr 2009 18:02:11 +0000</pubDate>
      <link>http://conceptsahead.com/off-axis/careful-with-that-configgem-eugene</link>
      <guid>http://conceptsahead.com/off-axis/careful-with-that-configgem-eugene</guid>
    </item>
  </channel>
</rss>
