<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Sketchpad - Dan Sketcher's personal blog</title>
	<atom:link href="http://www.dansketcher.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dansketcher.com</link>
	<description>Dan Sketcher on Rails, computers, and other junk</description>
	<pubDate>Wed, 09 Apr 2008 15:10:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>Running one migration by hand</title>
		<link>http://www.dansketcher.com/2008/03/25/running-one-migration-by-hand/</link>
		<comments>http://www.dansketcher.com/2008/03/25/running-one-migration-by-hand/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 16:37:31 +0000</pubDate>
		<dc:creator>dansketcher</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.dansketcher.com/2008/03/25/running-one-migration-by-hand/</guid>
		<description><![CDATA[Sometimes, you want to run a single migration by hand (to test it maybe&#8230;)
You can do this from the command line:

ruby script/runner 'require "db/migrate/005_create_blogs"; CreateBlogs.migrate(:down)'
ruby script/runner 'require "db/migrate/005_create_blogs"; CreateBlogs.migrate(:up)'

]]></description>
			<content:encoded><![CDATA[<p>Sometimes, you want to run a single migration by hand (to test it maybe&#8230;)</p>
<p>You can do this from the command line:</p>
<p><code><br />
ruby script/runner 'require "db/migrate/005_create_blogs"; CreateBlogs.migrate(:down)'<br />
ruby script/runner 'require "db/migrate/005_create_blogs"; CreateBlogs.migrate(:up)'<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dansketcher.com/2008/03/25/running-one-migration-by-hand/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DRYing up Actions with a page_errorhandler</title>
		<link>http://www.dansketcher.com/2008/03/09/drying-up-actions-with-a-page_errorhandler/</link>
		<comments>http://www.dansketcher.com/2008/03/09/drying-up-actions-with-a-page_errorhandler/#comments</comments>
		<pubDate>Sat, 08 Mar 2008 14:24:47 +0000</pubDate>
		<dc:creator>dansketcher</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.dansketcher.com/2008/03/09/drying-up-actions-with-a-page_errorhandler/</guid>
		<description><![CDATA[When I am developing page actions, I quite often find myself approaching a standard get/post action in the same way. This is particularly because I want to validate a number of ActiveRecord models, only progressing if they are ALL valid, and showing all errors at once
Of course, that means that I need to have a [...]]]></description>
			<content:encoded><![CDATA[<p>When I am developing page actions, I quite often find myself approaching a standard get/post action in the same way. This is particularly because I want to validate a number of ActiveRecord models, only progressing if they are ALL valid, and showing all errors at once</p>
<p>Of course, that means that I need to have a standard way of doing this, and a standard way of reporting it. It also implies the use of transactions, so that all saves are rolled back on failure. I have </p>
<p>So to begin with, an (hypothetical) example of my approach is:</p>
<p><code><br />
def edit_user<br />
  @user    = User.find(session[:user_id])<br />
  @address = @user.address<br />
  if request.post?<br />
    begin<br />
      # note that I do not want to reference the objects in the<br />
      # method call - so that the changes are available to render<br />
      @user.transaction do<br />
        results = []<br />
        results &lt;&lt; @user.save<br />
        results &lt;&lt; @address.save<br />
        raise &#8220;Validation failed&#8221; if results.include?(false)<br />
      end<br />
      redirect_to :action =&gt; :show_user and return<br />
    rescue Exception<br />
      logger.warn{&#8221;Transaction terminated : #{e.message}&#8221;}<br />
      logger.warn{&#8221;@user : #{(@user.errors.full_messages.join(&#8217;; &#8216;) rescue nil)}&#8221;}<br />
      logger.warn{&#8221;@address : #{(@address.errors.full_messages.join(&#8217;; &#8216;) rescue nil)}&#8221;}<br />
      logger.debug{e.backtrace}<br />
    end<br />
  end<br />
end<br />
</code></p>
<p>The first thing that is useful about this is that because all objects are saved together and the transaction is not terminated unless ONE of them is invalid, we will not redirect and the edit_user template will be rendered. Also, the validation errors are written to the log &#8220;just in case&#8221;</p>
<p>Also, note that I am using the log4r syntax of using braces instead of brackets. In Log4r, if the logger is not logging at the level that is specified, the code inside the braces will not be run. In the example above, if we are in production mode and we are not logging DEBUG, the e.backtrace method is actually not executed.</p>
<p>From here, lets DRY it up.</p>
<p>First, there&#8217;s those validation messages. There&#8217;s quite a lot of code here. I&#8217;ve approached this from 2 angles. First, in environment.rb, I put this code in</p>
<p><code><br />
class ActiveRecord::Base<br />
  def full_messages<br />
    self.errors.full_messages.join('; ') rescue nil<br />
  end<br />
end<br />
</code></p>
<p>and in application.rb<br />
<code><br />
  def validation_message(*objects)<br />
    str = "Validation error :"<br />
    objects.each{ |obj| str << "\n#{obj.class.name} => #{obj.full_messages}&#8221; }<br />
    str<br />
  end<br />
</code></p>
<p>This means that the validation message can now be handled by simply doing this in the rescue block:</p>
<p><code><br />
logger.warn{validation_message(@user, @address)}<br />
</code></p>
<p>Next, because I use this structure regularly, I created a page_errorhandler method to contain the exception block that does this:</p>
<p><code><br />
  def page_errorhandler(*objects, &#038;block)<br />
    begin<br />
      yield<br />
    rescue Exception => e<br />
      logger.warn{"Transaction terminated : #{e.message}"}<br />
      logger.warn{validation_message(*objects)}<br />
      logger.debug{e.backtrace}<br />
    end<br />
  end<br />
</code></p>
<p>Combining these with our method above:</p>
<p><code><br />
def edit_user<br />
  @user    = User.find(session[:user_id])<br />
  @address = @user.address<br />
  if request.post?<br />
    page_errorhandler(@user, @address) do<br />
      # note that I do not want to reference the objects in the<br />
      # method call - so that the changes are available to render<br />
      @user.transaction do<br />
        results = []<br />
        results << @user.save<br />
        results << @address.save<br />
        raise "Validation failed" if results.include?(false)<br />
      end<br />
      redirect_to :action => :show_user and return<br />
    end<br />
  end<br />
end<br />
</code></p>
<p>Neatens things up nicely!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dansketcher.com/2008/03/09/drying-up-actions-with-a-page_errorhandler/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Master Pages for Rails (or, Heirarchial Layouts)</title>
		<link>http://www.dansketcher.com/2008/03/07/master-pages-for-rails-or-heirarchial-layouts/</link>
		<comments>http://www.dansketcher.com/2008/03/07/master-pages-for-rails-or-heirarchial-layouts/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 14:54:28 +0000</pubDate>
		<dc:creator>dansketcher</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.dansketcher.com/2008/03/07/master-pages-for-rails-or-heirarchial-layouts/</guid>
		<description><![CDATA[One of the things that I like about the .net web application setup is the concept of Master Pages. The most common usage of this is if you have a Home Page that has a slightly different layot from the rest of the site, but you want to share the base DIV structure and assets [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that I like about the .net web application setup is the concept of Master Pages. The most common usage of this is if you have a Home Page that has a slightly different layot from the rest of the site, but you want to share the base DIV structure and assets without having to copy them into another layout&#8230; Keep it DRY!</p>
<p>Although there is no &#8220;out of the box&#8221; solution for sharing common layout setups in Rails except for using Partials, there is in fact a way of replicating this functionality. First, you need to be familiar with the ActionView::Helpers::CaptureHelper class and the methods in it.</p>
<p>So, what you do is create a container rhtml layout that contains the common layout elements, such as the base HTML and div structure.</p>
<p>container.rhtml<br />
<code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;<br />
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;<br />
&lt;head&gt;<br />
&lt;body&gt;<br />
  &lt;%= yield :layout -%&gt;<br />
&lt;/div&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
</code></p>
<p>From there, you can create as many other layouts that reference that container, such as one called application.rhtml:<br />
<code>&lt;% @content_for_layout = capture do %&gt;<br />
  &lt;div id='a_new_div' /&gt;<br />
  &lt;%= yield :layout %&gt;<br />
&lt;% end %&gt;<br />
&lt;%= render 'layouts/container', { 'content_for_layout' => @content_for_layout } %&gt;<br />
</code></p>
<p>Note what happens there - the capture method is used to catch the rendering of this layout file. Then, instead of just allowing it to render, this output is injected into the container.rhtml file. In this way, we have chained the inner layout (application.rhtml) into the outer (container.rhtml) layout.</p>
<p>In our example, the &#8220;&lt;div id=&#8217;a_new_div&#8217; /&gt;&#8221; will be injected, along with the data from the view, into the container. There is nothing stopping you from doing this to another layer, although I doubt how often you&#8217;d need to do that!</p>
<p>From our example above, we could also easily create a home.rhtml file that had slightly different layout from our application.rhtml file and use that from our HomeController without concern - all of the pages would then render in the correct layout while giving us the benefit of a shared outer container!</p>
<p>I have used this in production, and it works a treat both in terms of performance and code maintainability.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dansketcher.com/2008/03/07/master-pages-for-rails-or-heirarchial-layouts/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Guide to Electronic Music</title>
		<link>http://www.dansketcher.com/2007/08/11/guide-to-electronic-music/</link>
		<comments>http://www.dansketcher.com/2007/08/11/guide-to-electronic-music/#comments</comments>
		<pubDate>Fri, 10 Aug 2007 14:23:37 +0000</pubDate>
		<dc:creator>dansketcher</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.dansketcher.com/2007/08/11/guide-to-electronic-music/</guid>
		<description><![CDATA[I found this Guide to Electronic Music - it&#8217;s so comprehensive it makes my head spin&#8230; but now when someone ask me what I think of weird music variants I&#8217;ll be able to give them an answer  
]]></description>
			<content:encoded><![CDATA[<p>I found this <a href="http://www.di.fm/edmguide/edmguide.html" onClick="javascript:urchinTracker ('/outbound/article/www.di.fm');">Guide to Electronic Music</a> - it&#8217;s so comprehensive it makes my head spin&#8230; but now when someone ask me what I think of weird music variants I&#8217;ll be able to give them an answer <img src='http://www.dansketcher.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dansketcher.com/2007/08/11/guide-to-electronic-music/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ZFS Boot with NextentaOS</title>
		<link>http://www.dansketcher.com/2007/08/09/zfs-boot/</link>
		<comments>http://www.dansketcher.com/2007/08/09/zfs-boot/#comments</comments>
		<pubDate>Thu, 09 Aug 2007 13:26:56 +0000</pubDate>
		<dc:creator>dansketcher</dc:creator>
		
		<category><![CDATA[solaris]]></category>

		<category><![CDATA[zfs]]></category>

		<guid isPermaLink="false">http://www.dansketcher.com/2007/08/09/zfs-boot/</guid>
		<description><![CDATA[Little bit behind the 8-ball on posting this, but I came across this post at AspiringSysadmin.com - ZFS boot without having to manually set it up like you currently have to do with OpenSolaris.
NexentaOS is a GNU operating system that uses apt on top of the OpenSolaris kernel and runtime. It looks to me as [...]]]></description>
			<content:encoded><![CDATA[<p>Little bit behind the 8-ball on posting this, but I came across <a href="http://aspiringsysadmin.com/blog/2007/06/25/playing-with-zfs-boot-on-nexenta/" onClick="javascript:urchinTracker ('/outbound/article/aspiringsysadmin.com');">this post</a> at <a href="http://aspiringsysadmin.com" onClick="javascript:urchinTracker ('/outbound/article/aspiringsysadmin.com');">AspiringSysadmin.com</a> - ZFS boot without having to <a href="http://www.opensolaris.org/os/community/zfs/boot/" onClick="javascript:urchinTracker ('/outbound/article/www.opensolaris.org');">manually set it up</a> like you currently have to do with OpenSolaris.</p>
<p>NexentaOS is a GNU operating system that uses <strong>apt</strong> on top of the OpenSolaris kernel and runtime. It looks to me as though the <a href="http://www.gnusolaris.org/" onClick="javascript:urchinTracker ('/outbound/article/www.gnusolaris.org');">www.gnusolaris.org</a> site has been abandoned for the <a href="http://www.genunix.org/" onClick="javascript:urchinTracker ('/outbound/article/www.genunix.org');">GenUnix </a> <a href="http://www.genunix.org/distributions/gnusolaris/" onClick="javascript:urchinTracker ('/outbound/article/www.genunix.org');">NextentaOS</a> site, which is a shame because it&#8217;s damn hard to find on Google. The GenUnix site actually also hosts the <a href="http://www.genunix.org/distributions/belenix_site/" onClick="javascript:urchinTracker ('/outbound/article/www.genunix.org');">Belenix</a> and <a href="http://www.genunix.org/distributions/schillix/" onClick="javascript:urchinTracker ('/outbound/article/www.genunix.org');">Schillix</a> sites as well, with Belenix a LiveCD, and Schillix a rebuilt OpenSolaris distro.</p>
<p>The AspringSysadmin went into how to set NextentaOS in VMWare - my quest now is to combine VMWare, NextentaOS ZFS Boot and 2&#215;750GB drives in RaidZ configuration&#8230; I hope it works!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dansketcher.com/2007/08/09/zfs-boot/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JRuby-OpenSSL and HTTP request timeouts (in ActiveSalesforce)</title>
		<link>http://www.dansketcher.com/2007/07/20/jruby-openssl-and-http-request-timeouts-in-activesalesforce/</link>
		<comments>http://www.dansketcher.com/2007/07/20/jruby-openssl-and-http-request-timeouts-in-activesalesforce/#comments</comments>
		<pubDate>Thu, 19 Jul 2007 15:29:16 +0000</pubDate>
		<dc:creator>dansketcher</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<category><![CDATA[jruby]]></category>

		<guid isPermaLink="false">http://www.dansketcher.com/2007/07/20/jruby-openssl-and-http-request-timeouts-in-activesalesforce/</guid>
		<description><![CDATA[So, JRuby looks pretty cool, and I&#8217;ve got some code written that uses a weird BouncyCastle encryption implementation going in my rails app. Works well, the WAR deployment works (with goldspike) and everything&#8217;s going swimmingly.
Until, of course, I tried to integrate with Another Project that uses the ActiveSalesforce. Behind the scenes, ActiveSalesforce makes SSL encrypted [...]]]></description>
			<content:encoded><![CDATA[<p>So, JRuby looks pretty cool, and I&#8217;ve got some code written that uses a weird BouncyCastle encryption implementation going in my rails app. Works well, the WAR deployment works (with <a href="svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike" onClick="javascript:urchinTracker ('/outbound/article/rubyforge.org');">goldspike</a>) and everything&#8217;s going swimmingly.</p>
<p>Until, of course, I tried to integrate with Another Project that uses the <a href="http://wiki.apexdevnet.com/index.php/ActiveSalesforce" onClick="javascript:urchinTracker ('/outbound/article/wiki.apexdevnet.com');">ActiveSalesforce</a>. Behind the scenes, ActiveSalesforce makes SSL encrypted connections to Salesforce API endpoints and performs operations. This was working fine until I started the app under JRuby. All of a sudden, the salesforce connections stopped working.</p>
<p>A bit of digging later, and I discovered that the JRuby-OpenSSL implementation is causing reads of the HTTP responses to stall. JRuby HTTP is fine, Ruby HTTPS is fine, but JRuby HTTPS is not. Boo.</p>
<p><a href="http://jira.codehaus.org/browse/JRUBY-1222" onClick="javascript:urchinTracker ('/outbound/article/jira.codehaus.org');">It&#8217;s a bug</a>, now. I hope it&#8217;s fixed soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dansketcher.com/2007/07/20/jruby-openssl-and-http-request-timeouts-in-activesalesforce/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Integrating Log4r and Ruby on Rails</title>
		<link>http://www.dansketcher.com/2007/06/16/integrating-log4r-and-ruby-on-rails/</link>
		<comments>http://www.dansketcher.com/2007/06/16/integrating-log4r-and-ruby-on-rails/#comments</comments>
		<pubDate>Fri, 15 Jun 2007 14:10:36 +0000</pubDate>
		<dc:creator>dansketcher</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<category><![CDATA[log4r]]></category>

		<guid isPermaLink="false">http://www.dansketcher.com/2007/06/16/integrating-log4r-and-ruby-on-rails/</guid>
		<description><![CDATA[Aaaaaaaages ago, I wrote a message on the mailing list (before it moved to Google Groups!) about how to integrate Rails and Log4r. Since then a little bit has changed and that way may or may not entirely work any more. Since then, aaaaages ago Jason Rimmer asked me to update so that it&#8217;s all [...]]]></description>
			<content:encoded><![CDATA[<p>Aaaaaaaages ago, I wrote a message on the mailing list (before it moved to Google Groups!) about how to integrate Rails and Log4r. Since then a little bit has changed and that way may or may not entirely work any more. Since then, aaaaages ago Jason Rimmer asked me to update so that it&#8217;s all new and fresh, but I completely forgot in the move to the UK (very sorry Jason!). So here it is.</p>
<p>I&#8217;ve got a few outputters. One that acts like the default outputter, that writes &#8220;development.log&#8221; and so on. Then another that outputs to standard error for console lovin&#8217; (in dev mode). Then another that uses a date file outputter to automatically roll over logs every day (for production mode), and finally an Email outputter that only runs in production and sends an email of the log for ERROR and FATAL log levels.</p>
<p><a href='http://www.dansketcher.com/wp-content/uploads/2007/06/log4r_rails.zip' title='log4r rails configuration'>Log4r Rails configuration files</a></p>
<p>The first bit is the configuration YAML file, which is used to configure the loggers. Then there is logger.rb, which turns on and off the outputters as required. The final part is to include this logger.rb into the application configuration.</p>
<p>It is VERY IMPORTANT that you include the file before the call to the <strong>Rails::Initializer.run do</strong> block. This is because in this section of code the RAILS_DEFAULT_LOGGER is initialised, and if we don&#8217;t get in before that, we won&#8217;t get our logger injected into the Rails framework stack. So, configure it like this:</p>
<pre>
require File.join(File.dirname(__FILE__), 'boot')

require File.expand_path(File.dirname(__FILE__) + "/logger")

Rails::Initializer.run do |config|
...
</pre>
<p>Just drop the require line in there and it will load logger.rb, which loads log4r.yaml, and everything is up and going. You&#8217;ll see friendly [DEBUG] lines in your console and everthing! Of course, I prefer verbose logging on the console in development; you may not, customise by reading the <a href="http://log4r.sourceforge.net/manual.html" onClick="javascript:urchinTracker ('/outbound/article/log4r.sourceforge.net');">log4r manual</a>. Of course, if you expect your error mails to be delivered, change the SMTP server settings at the bottom of the yaml file.</p>
<p>Sorry for the delay Jason!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dansketcher.com/2007/06/16/integrating-log4r-and-ruby-on-rails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rails composite primary key support</title>
		<link>http://www.dansketcher.com/2007/06/13/rails-composite-primary-key-support/</link>
		<comments>http://www.dansketcher.com/2007/06/13/rails-composite-primary-key-support/#comments</comments>
		<pubDate>Wed, 13 Jun 2007 10:53:23 +0000</pubDate>
		<dc:creator>dansketcher</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.dansketcher.com/2007/06/13/rails-composite-primary-key-support/</guid>
		<description><![CDATA[I am working with a legacy database. Usually, the built in rails stuff for table prefixing and primary key changes is enough. Sometimes, it&#8217;s not.
I had a problem with a join table that has Foreign Key names that are tablename_id, but the tables they reference is tablename_id as well. The has_and_belongs_to_many method DID NOT like [...]]]></description>
			<content:encoded><![CDATA[<p>I am working with a legacy database. Usually, the built in rails stuff for table prefixing and primary key changes is enough. Sometimes, it&#8217;s not.</p>
<p>I had a problem with a join table that has Foreign Key names that are tablename_id, but the tables they reference is tablename_id as well. The <em>has_and_belongs_to_many</em> method DID NOT like it at all. Added to this is that there are attributes in the join table (is_primary) that I need to use. I considered (and discussed with the Java devs) the option of making the join table have an ID and making it a model, but there was potential for breakage and I like to tred very carefully around the existing app and making changes.</p>
<p>So, a bit of time on Google later, and I came across Nic Williams&#8217; <a href="http://compositekeys.rubyforge.org/" onClick="javascript:urchinTracker ('/outbound/article/compositekeys.rubyforge.org');">Composite Primary Key</a> plugin. Oh man, it works a treat. I created the model for the join table, specified the primary key<em>s</em>, and went as normal!</p>
<p>Beautiful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dansketcher.com/2007/06/13/rails-composite-primary-key-support/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Wordpress &#60;code&#62; and &#60;pre&#62; formatting</title>
		<link>http://www.dansketcher.com/2007/06/07/wordpress-code-and-pre-formatting/</link>
		<comments>http://www.dansketcher.com/2007/06/07/wordpress-code-and-pre-formatting/#comments</comments>
		<pubDate>Thu, 07 Jun 2007 08:34:21 +0000</pubDate>
		<dc:creator>dansketcher</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.dansketcher.com/2007/06/07/wordpress-code-and-pre-formatting/</guid>
		<description><![CDATA[After the last paste-heavy post, I finally got around to doing something about wordpress&#8217;s formatting of code blocks. This site was very helpful:
http://tjulo.blogspot.com/2007/03/wordpress-and-source-code-posts.html
So, edit the file wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js.
Comment out the section that replaces pre content:

/* var startPos = -1;
while ((startPos = content.indexOf('
', startPos+1);
var innerPos = content.indexOf('>', startPos+1);
var chunkBefore = content.substring(0, innerPos);
var chunkAfter = content.substring(endPos);

var innards = [...]]]></description>
			<content:encoded><![CDATA[<p>After the last paste-heavy post, I finally got around to doing something about wordpress&#8217;s formatting of code blocks. This site was very helpful:</p>
<p><a href="http://tjulo.blogspot.com/2007/03/wordpress-and-source-code-posts.html" onClick="javascript:urchinTracker ('/outbound/article/tjulo.blogspot.com');">http://tjulo.blogspot.com/2007/03/wordpress-and-source-code-posts.html</a></p>
<p>So, edit the file wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js.</p>
<p>Comment out the section that replaces <em>pre</em> content:</p>
<pre>
/* var startPos = -1;
while ((startPos = content.indexOf('
<pre', var="" endpos="content.indexOf('<pr>">', startPos+1);
var innerPos = content.indexOf('>', startPos+1);
var chunkBefore = content.substring(0, innerPos);
var chunkAfter = content.substring(endPos);

var innards = content.substring(innerPos, endPos);
innards = innards.replace(/\n/g, '
');
content = chunkBefore + innards + chunkAfter;
}*/
</pre>
<p>Then I had to update my CSS so that <em>pre</em> used the same class as <em>code</em> and then change my posts over to use <em>pre</em> instead of <em>code</em>.</p>
<p>Next step is to fix <em>code</em> too so that I don&#8217;t have to think about it.</p>
<p>It does seem to have the side-effect of not automatically handling the escaping of &lt; and &gt; symbols outside those tags though, which for this post where I started with &lt;code&gt; and &lt;pre&gt; instead of <em>code</em> and <em>pre</em>, made things a bit of a mess.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dansketcher.com/2007/06/07/wordpress-code-and-pre-formatting/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rails ActionWebService SOAP error &#8220;No valid method call - missing method name&#8221;</title>
		<link>http://www.dansketcher.com/2007/06/06/rails-actionwebservice-soap-error-no-valid-method-call-missing-method-name/</link>
		<comments>http://www.dansketcher.com/2007/06/06/rails-actionwebservice-soap-error-no-valid-method-call-missing-method-name/#comments</comments>
		<pubDate>Wed, 06 Jun 2007 13:42:48 +0000</pubDate>
		<dc:creator>dansketcher</dc:creator>
		
		<category><![CDATA[Rails]]></category>

		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://www.dansketcher.com/2007/06/06/rails-actionwebservice-soap-error-no-valid-method-call-missing-method-name/</guid>
		<description><![CDATA[For a Salesforce.com integration project, I need to create a SOAP server to accept messages from Salesforce. Seeing as there is no way directly import a wsdl into ActionWebService, I instead used wsdl2ruby from the soap4r distribution to generate server stubs. Then, I used ActionWebService to emulate the same service. I had problems with using [...]]]></description>
			<content:encoded><![CDATA[<p>For a Salesforce.com integration project, I need to create a SOAP <em>server</em> to accept messages from Salesforce. Seeing as there is no way directly import a wsdl into ActionWebService, I instead used wsdl2ruby from the soap4r distribution to generate server stubs. Then, I used ActionWebService to emulate the same service. I had problems with using the default layout, so I changed my structure to use a delegated structure:</p>
<pre>
class NotificationServiceController < ApplicationController
  web_service_dispatching_mode :delegated
  web_service_scaffold :invoke
  web_service :notifications, NotificationService.new
end
</pre>
<pre>
class NotificationServiceApi < ActionWebService::API::Base
  inflect_names false
  require_soap_action_header false
  api_method :notifications,
             :expects => [Notifications],
             :returns => [:bool]
end
</pre>
<pre>
class NotificationService < ActionWebService::Base
  web_service_api NotificationServiceApi
  def logger
    RAILS_DEFAULT_LOGGER
  end
  def notifications(organization_id, action_id, session_id, enterprise_url, partner_url, notification)
    my_object_id = notification.sObject.id
    ack = false
    begin
      ack = so_something(my_object_id)
    rescue Exception => e
      logger.error("Error processing payment: #{e.message}")
    end
    ack
  end
end
</pre>
<p>But STILL SOMETHING WAS WRONG. I was getting &#8220;No valid method call - missing method name&#8221; with the Salesforce outbound message queue reporting &#8220;org.xml.sax.SAXParseException: Content is not allowed in prolog.&#8221; MMmmmmm helpful. The stack trace was showing that rails was trying to process the request as XMLRPC not SOAP, which was all wrong.</p>
<p>The stack trace looked something like this:</p>
<pre>
RuntimeError (No valid method call - missing method name!):
    /usr/lib/ruby/1.8/xmlrpc/parser.rb:476:in `parseMethodCall'
    /usr/lib/ruby/1.8/xmlrpc/marshal.rb:63:in `load_call'
    /usr/lib/ruby/1.8/xmlrpc/marshal.rb:32:in `load_call'
    /vendor/rails/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb:36:in `decode_request'
    /vendor/rails/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb:32:in `decode_action_pack_request'
    /vendor/rails/actionwebservice/lib/action_web_service/protocol/discovery.rb:20:in `discover_web_service_request'
    /vendor/rails/actionwebservice/lib/action_web_service/protocol/discovery.rb:18:in `discover_web_service_request'
    /vendor/rails/actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb:49:in `dispatch_web_service_request'
    (eval):1:in `notifications'
..........
</pre>
<p>Then, I came across <a href="http://dev.rubyonrails.org/ticket/7077" onClick="javascript:urchinTracker ('/outbound/article/dev.rubyonrails.org');">patch 7077</a> (indirectly via <a href="http://www.nabble.com/SOAP---missing-method-name-t2472401.html" onClick="javascript:urchinTracker ('/outbound/article/www.nabble.com');">this</a> and then <a href="http://www.google.co.uk/search?q=SoapAction+rails" onClick="javascript:urchinTracker ('/outbound/article/www.google.co.uk');">this</a>), so, using my new best friend <a href="http://piston.rubyforge.org/" onClick="javascript:urchinTracker ('/outbound/article/piston.rubyforge.org');">Piston</a> I checked out Rails 1.2.3 into vendor/rails, and patched with the diff in the change. It was not entirely smooth - the xmlrpc.rb file could not be patched, but I merged the change manually.</p>
<p>All done! Works!</p>
<p>One thing I did discover the hard way though is that you need to have the whole stack of definitions with the same naming scheme for this to work. That is, if you&#8217;ve got a <strong>NotificationServiceController</strong>, you need to ensure that you have a <strong>NotificationService</strong> and a <strong>NotificationServiceApi</strong> defined and in use - no other class names will work. No Reuse of API Definitions, which is a bit of a bugger.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dansketcher.com/2007/06/06/rails-actionwebservice-soap-error-no-valid-method-call-missing-method-name/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.455 seconds -->
