<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>benrobb &#187; Rails</title>
	<atom:link href="http://benrobb.com/category/tech/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://benrobb.com</link>
	<description>thoughts that don&#039;t fit in</description>
	<lastBuildDate>Wed, 11 May 2011 16:56:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Good &amp; Cheap Rails Hosting?</title>
		<link>http://benrobb.com/2007/08/21/good-cheap-rails-hosting/</link>
		<comments>http://benrobb.com/2007/08/21/good-cheap-rails-hosting/#comments</comments>
		<pubDate>Tue, 21 Aug 2007 14:37:37 +0000</pubDate>
		<dc:creator>benrobb</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://benrobb.com/2007/08/21/good-cheap-rails-hosting/</guid>
		<description><![CDATA[Can anyone tell me where to find it?  Does it even exist? I&#8217;ve been looking for a good Rails host recently, one that&#8217;s running Apache/Mongrel or something business class.  Apache mod_ruby was a terrible at best, FastCGI was better at handling threads and serving content, but now that we&#8217;ve got a native Ruby solution, that [...]]]></description>
			<content:encoded><![CDATA[<p>Can anyone tell me where to find it?  Does it even exist?</p>
<p>I&#8217;ve been looking for a good Rails host recently, one that&#8217;s running Apache/Mongrel or something business class.  Apache mod_ruby was a terrible at best, FastCGI was better at handling threads and serving content, but now that we&#8217;ve got a native Ruby solution, that seems the best way to go.</p>
<p>But it&#8217;s so expensive (at least for a personal blog).  I&#8217;ve looked at <a href="http://www.mediatemple.net/" title="Media Temple">MediaTemple</a>, which looks like a great option, but the basic Ruby package is $20/month.  In the days of cheap hosts that seems quite a high monthly price.</p>
<p>Then there&#8217;s <a href="http://www.hostingrails.com/" title="Hosting Rails">HostingRails</a> which has a basic Ruby package starting at $3.79/month, but if you want the Mongrel package, that&#8217;ll cost you $9.79/month.  That&#8217;s obviously a better deal, but they claim to be RoR developers since 2005 and their website would suggest otherwise.  It&#8217;s not too badly designed, but I typically expect a much better look from a Rails developer.  It&#8217;s just not the kinda place that I feel like I could trust with my credit card number.</p>
<p>So have I missed something?  What&#8217;s the cheapest Mongrel-running host I can find out there?  Does HostMonster support Mongrel?  I know Bluehost doesn&#8217;t.  Does anybody have experience with <a href="http://www.lunarpages.com/index.php" title="lunar pages">lunarpages</a>,  <a href="http://www.midphase.com/" title="midphase">MidPhase</a>, or <a href="http://www.anhosting.com/" title="an hosting">An</a>?  Please help me out in the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://benrobb.com/2007/08/21/good-cheap-rails-hosting/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rails &amp; MemcacheD</title>
		<link>http://benrobb.com/2007/03/13/rails-memcached/</link>
		<comments>http://benrobb.com/2007/03/13/rails-memcached/#comments</comments>
		<pubDate>Wed, 14 Mar 2007 04:38:30 +0000</pubDate>
		<dc:creator>benrobb</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://benrobb.com/2007/03/13/rails-memcached/</guid>
		<description><![CDATA[Well, after spending a few frustrated hours on Saturday, I&#8217;ve got a working application that uses memcached. And when I use the word application, I use it very loosely. It&#8217;s basically a page that sets the current time into the session. Now originally I followed this tutorial and installed the necessary gems in order to [...]]]></description>
			<content:encoded><![CDATA[<p>Well, after spending a few frustrated hours on Saturday, I&#8217;ve got a working application that uses memcached.  And when I use the word application, I use it very loosely.  It&#8217;s basically a page that sets the current time into the session.</p>
<p>Now originally I followed <a href="http://nubyonrails.com/articles/2006/08/17/memcached-basics-for-rails" title="nuby on rails">this tutorial</a> and installed the necessary gems in order to cache the ActiveRecord objects into memcached.  I followed all instructions exactly as instructed, but starting the memcached server in verbose mode, revealed no object calls to and from the cache.  If I loaded up the application console, I could access the cache directly and put things in on my own, but the functionality provided by cached_model was not working on my machine for whatever reason.</p>
<p>Being somewhat of a nuby anyway when it comes to Rails, I turned to an alternate solution rather than hopelessly debugging the current problem.  I found <a href="http://townx.org/blog/elliot/ruby_tuesday_what_ive_learned_about_rails_and_memcache" title="Ruby Tuesday">another tutorial</a> that had instructions on how to cache sessions into memcached.  I used the memcache-client client rather than the Ruby-memcache client going for the speed and the ease of setup.  It works like a charm.</p>
<p>Now rather than just leaving it there, I&#8217;ll tell you what I&#8217;v discovered over and above what Elliott discovered over at townx.  The ongoing development of memcache-client has apparently made some advancements to the point where it matches the application stability of Ruby-memcache when the memcache server is turned off.</p>
<p>At the time of the post, Elliott observed that when using memcache-client the whole application fell over when the connection to the memcache server was lost, while Ruby-memcache kept the application running with irretrievably broken sessions.  He then wrote a plug-in that monitored the memcache servers and when they came back online would begin using them again (rather than having to restart the application).  My observation as of today is that memcache-client now has both of those functionalities built in.</p>
<p>When the connection to the memcache server is lost, then the sessions are broken, any data stored is inaccessible, however when the memcache servers some back online, the application recognizes that and begins using the sessions again.  If the memcache server was turned off, then any data in them is gone as well, but if the memcache server itself was still running and it was just the connection lost, then the session data should still be available in the memcache servers.</p>
<p>As a sidenote, over at Nuby on Rails, they noted that the the memcached server available on Macs through Darwinports is broken.  I verified this; the calls I made to the cache directly from the console did indeed take 5 seconds to  push through.  However,when running it from my Ubuntu box even over the internet (Sundance to Orem) the application response was pretty snappy.  Not to shabby considering the quality of the internet in Sundance.</p>
]]></content:encoded>
			<wfw:commentRss>http://benrobb.com/2007/03/13/rails-memcached/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cannot Map {objType} to SOAP/OM</title>
		<link>http://benrobb.com/2007/02/06/cannot-map-objtype-to-soapom/</link>
		<comments>http://benrobb.com/2007/02/06/cannot-map-objtype-to-soapom/#comments</comments>
		<pubDate>Wed, 07 Feb 2007 04:03:56 +0000</pubDate>
		<dc:creator>benrobb</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://benrobb.com/2007/02/06/cannot-map-objtype-to-soapom/</guid>
		<description><![CDATA[This was a strange exception that I struggled with for several hours this evening, but I have finally prevailed. The Background For my Information Architecture class, we&#8217;ve got to create a web service provider and a web service requester, this provided the initial impetus for my recent push into web services and the last few [...]]]></description>
			<content:encoded><![CDATA[<p>This was a strange exception that I struggled with for several hours this evening, but I have finally prevailed.</p>
<p><strong>The Background</strong><br />
For my Information Architecture class, we&#8217;ve got to create a web service provider and a web service requester, this provided the initial impetus for my recent push into web services and the last few posts dedicated to the topic.  Now our professor has published a web service that basically dumps his database out into an array of complex data types.</p>
<p>His database is a weather reporting database that has zip code, temperature, humidity, etc.  The databse is small (currently 3 entries) and populated with completely fabricated data, this is a learning experience not an accurate forecaster.</p>
<p>Our task is to subscribe to his web service, and publish our own that will accept a string parameter as the zip code and return the single weather report for just that zip code.  I decided that I&#8217;d just subscribe to his web service in my controller, find the appropriate weather report, create my own Struct for my web service, and push it out to my subscribers.</p>
<p><strong>The Problem</strong><br />
Once I had received my professor&#8217;s SOAP object back, I stepped into it to retrieve the zip codes from each entry.  When I found the matching zip code, I mapped his keys and values to my own with a line of code like this:</p>
<p><code>return WeatherReport.new(:cityzip =&gt; row.cityzip, :temperature =&gt; row.temperature, :etc =&gt; ad naseum)</code></p>
<p>There are ten different attributes that my object must return to my subscribers, so it was slightly tedious to put all these things together.  I prevailed.</p>
<p>When subscribing to my own web service via WSDL, however, I received the following exception:</p>
<p><code>Exception: Cannot map WeatherReport to SOAP/OM</code></p>
<p>WeatherReport is the name of the Struct that I was using as my return type.  I began meticulously checking all my code.  I had already written code to subscribe directly to my professor&#8217;s web service, so I checked the SOAP object coming back from that.  I used a copy of the same code to subscribe in my own web service and could not figure out what was going on (hours pass).</p>
<p>I finally ran across <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/211011">this email archive</a> that had a fix, but not an answer.</p>
<p><strong>The Fix</strong><br />
I had to change my code to this:</p>
<p><code>return WeatherReport.new(:cityzip =&gt; "#{row.cityzip}", :temperature =&gt; "#{row.temperature}", :etc =&gt; "#{ad naseum}")</code></p>
<p>The &#8220;#{row.cityzip}&#8221; means that the object inside the {} should be interpreted as a variable and it&#8217;s value should appear in the string instead of the variable name.  It&#8217;s just a shorthand way of concatenating strings with the values stored in string variables (and in case you were wondering, yes, you must use double quotes or it won&#8217;t work).</p>
<p>Now the most interesting thing about this error is that <code>row.cityzip == "#{row.cityzip}"</code>, meaning that the expression evalutates to <code>true</code>.  For all intents and purposes, these two strings are exactly the same.</p>
<p>Peter (the guy with the fix) speculates on what might be the cause, but he was also using the a Struct (via SOAP4R), so I assume that the problem&#8217;s source may lie in that class.  Given the dearth of readily available information on the topic, I hope you find this useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://benrobb.com/2007/02/06/cannot-map-objtype-to-soapom/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WSDL, Rails, &amp; Complex Data Types</title>
		<link>http://benrobb.com/2007/02/05/wsdl-rails-complex-data-types/</link>
		<comments>http://benrobb.com/2007/02/05/wsdl-rails-complex-data-types/#comments</comments>
		<pubDate>Mon, 05 Feb 2007 22:14:20 +0000</pubDate>
		<dc:creator>benrobb</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://benrobb.com/2007/02/05/wsdl-rails-complex-data-types/</guid>
		<description><![CDATA[This could also be considered part three of my HowTo: Put WSDL on Rails series, but it&#8217;s not really a HowTo in the strictest sense of the word. Therefore, this article is more of a monologue than a set of instructions. If you&#8217;ve stuck with me this far you&#8217;ve probably figured out that I&#8217;m discovering [...]]]></description>
			<content:encoded><![CDATA[<p>This could also be considered part three of my HowTo: Put WSDL on Rails series, but it&#8217;s not really a HowTo in the strictest sense of the word.  Therefore, this article is more of a monologue than a set of instructions.</p>
<p>If you&#8217;ve stuck with me this far you&#8217;ve probably figured out that I&#8217;m discovering things on my own shortly before I spew them all out here.  In <a href="http://benrobb.com/2007/01/30/howto-put-wsdl-on-rails/" title="Howto put WSDL on Rails">Howto: Put WSDL on Rails</a> we built a simple web service that would accept a string parameter, modify it, and send the modified version back to the user.  In <a href="http://benrobb.com/2007/02/01/howto-put-wsdl-on-rails-part-2/" title="Howto put WSDL on Rails [part 2]">Part 2</a>, we subscribed to (and used) that same web service using only the WSDL.  At the time I thought I was done, but as I&#8217;ve played around a bit more, I realized that there was another major part of web services.  So now we&#8217;ll cover dealing with complex data types.</p>
<p>I began by wondering what kinds of things besides [:string] you could pass as parameters to and from a web service.  I finally happened upon the Ruby on Rails manual that somehow I had not discovered up to this point.  Why don&#8217;t these pages come up higher in the Google search results?  Rails uses ActionWebService to interact with web services of all kinds and you can find the beginning of the manual <a href="http://manuals.rubyonrails.com/read/chapter/67" title="What is Action Web Service?">here</a>.  You can find the specific answers to my questions <a href="http://manuals.rubyonrails.com/read/chapter/68" title="Defining an API">here</a> and <a href="http://api.rubyonrails.org/classes/ActionWebService/SignatureTypes.html" title="SignatureTypes">here</a>.</p>
<p>After reading this and mulling it over a bit, everything was pretty clear except for the so-called Structured Type parameters.  I set out to gain a better understanding of this, and this is what I accomplished.  First off, you&#8217;ll want to read up an something called a <a href="http://api.rubyonrails.org/classes/ActionWebService/Struct.html" title="Struct">Struct</a>.  In essence an ActionWebService::Struct is a special kind of object that can be used for web services, but doesn&#8217;t have any ties to a database like an ActiveRecord::Base object.</p>
<p>I first defined a new struct in <strong>app/models/weather_report.rb</strong> of my WebServiceProvider.</p>
<p><code>class WeatherReport &lt; ActionWebService::Struct<br />
member :zip, :int<br />
member :temp, :int<br />
member :wind_speed, :int<br />
member :wind_direction, :string<br />
end<br />
</code></p>
<p>I then created the proper method in my API at <strong>app/apis/weather_api.rb</strong>:</p>
<p><code>api_method :get_weather, :expects =&gt; [:string], :returns =&gt; [WeatherReport]</code></p>
<p>And since I was really just curious to see how this works, I defined a very dynamic method in <strong>app/controllers/weather_controller.rb</strong>:</p>
<p><code>def get_weather(zip_code)<br />
return WeatherReport.new(:zip =&gt; 84097, :temp =&gt; 55, :wind_speed =&gt; 5, :wind_direction =&gt; 'SW')<br />
end</code></p>
<p>And that&#8217;s really all there is to it.  If you&#8217;ve got a database driven application you could simply pass in one of the models that corresponds to a table on your database.  So instead of an ActionWebService::Struct you could just pass in an ActiveRecord::Base object with the exact same syntax.</p>
<p>Now to see what comes out on the other end.  In another application, I subscribed to my web service and in my view put <code>&lt;%= debug @result %&gt;</code> with <code>@result</code> being the result of my GetWeather call to the web service.</p>
<p>The debugged results came out like this.</p>
<p><code>#&lt;soap::mapping::object:0x14868c6 {}zip="84097" {}wind_direction="SW" {}wind_speed="5" {}temp="55"&gt;</code></p>
<p>Carrying this logical line one step further, if a web service required a complex data type as input, we could build an ActionWebService::Struct object or use an appropriate ActiveRecord::Base object to pass into a third party web service.  I see the struct option being much more useful ona day to day basis, but in a B2B environment, you can start to see a place for some real hard-core service interactions passing full-blown database-drive object types around between systems.</p>
<p>As I began to play around with web services, I thought they were pretty neat, but I&#8217;m beginning to see the how powerful they could be given the right set of circumstances.</p>
]]></content:encoded>
			<wfw:commentRss>http://benrobb.com/2007/02/05/wsdl-rails-complex-data-types/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Howto: Put WSDL on Rails [Part 2]</title>
		<link>http://benrobb.com/2007/02/01/howto-put-wsdl-on-rails-part-2/</link>
		<comments>http://benrobb.com/2007/02/01/howto-put-wsdl-on-rails-part-2/#comments</comments>
		<pubDate>Fri, 02 Feb 2007 06:22:12 +0000</pubDate>
		<dc:creator>benrobb</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://benrobb.com/2007/02/01/howto-put-wsdl-on-rails-part-2/</guid>
		<description><![CDATA[In the first article about WSDL on Rails we created our own web service that accepted a string, modified it, and returned a new string. Now we&#8217;ll take a look at creating another application that can consume or subscribe to our web service. This is almost too easy. I figure the best way to demonstrate [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://benrobb.com/2007/01/30/howto-put-wsdl-on-rails/" title="howto put WSDL on rails">the first article</a> about WSDL on Rails we created our own web service that accepted a string, modified it, and returned a new string.  Now we&#8217;ll take a look at creating another application that can consume or subscribe to our web service.  This is almost too easy.  I figure the best way to demonstrate the simplicity is to keep this article as short as possible.</p>
<p><strong>1. Fire up the old WebServiceProvider application that we created in Part 1</strong></p>
<p>From the application root directory type <code>./script/server</code></p>
<p><strong>2.  Create a new WebServiceConsumer application</strong></p>
<p>In a new terminal window type <code>rails WebServiceConsumer</code></p>
<p><strong>3. Create a controller for your service consumer</strong></p>
<p><code>cd WebServiceConsumer<br />
./script/generate controller consumer</code></p>
<p><strong>4. Subscribe to your WebServiceProvider using its WSDL</strong></p>
<p>Open up your consumer_controller.rb in app/controllers.  It will be empty and it needs to look like this:</p>
<p><code>class ConsumerController &lt; ApplicationController</code></p>
<p><code>  require 'soap/wsdlDriver'</code></p>
<p><code>  def subscribe<br />
if params[:terms] == nil<br />
@service_output = ""<br />
else<br />
url = "http://localhost:3000/subscription/service.wsdl"<br />
factory = SOAP::WSDLDriverFactory.new(url)<br />
service = factory.create_rpc_driver<br />
@service_output = service.Subscribe(params[:terms])<br />
end<br />
end<br />
end<br />
</code><br />
This is where the magic happens.  The line <code>require 'soap/wsdlDriver'</code> brings in the needed Ruby library.  The subscribe method is simply an action like any other in your application.  We&#8217;re going to create a form that accepts some user input and then we&#8217;ll pass them on to our WebServiceProvider.  The url, factory, and service lines could all be done in one line, but I&#8217;ve broken them out here to demonstrate.</p>
<p>If the box is left blank, we don&#8217;t do anything.  If the user inputs some data, then we have a little bit of work to do.  We create a new service object based on the WebServiceProvider&#8217;s description of itself as defined by its WSDL.  Then our local <strong>service</strong> object acts as a proxy and any method calls we make on the local object are simply passed on to it the actual WebServiceProvider.</p>
<p>We can then define our <code>@service_output</code> as a variable we can then call in our view.  Now for testing.</p>
<p><strong>5.  Create two views for testing</strong></p>
<p>In app/views/consumer create an index.rhtml file as follows:<br />
<code><br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;WebServiceConsumer&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;h1&gt;WebServiceConsumer&lt;/h1&gt;<br />
&lt;p&gt;<br />
Enter your terms below. They will be passed on to our web service and you'll be able to see the response.<br />
&lt;/p&gt;</code></p>
<p><code>    &lt;%= start_form_tag :action=&gt; 'subscribe' %&gt;<br />
&lt;p&gt;&lt;label&gt;Terms&lt;/label&gt;&lt;br/&gt;<br />
&lt;%= text_field 'terms', '' %&gt;&lt;/p&gt;<br />
&lt;%= submit_tag "Subscribe" %&gt;<br />
&lt;%= end_form_tag %&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code></p>
<p>Also in app/views/consumer create subscribe.rhtml as follows:<br />
<code><br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;WebServiceConsumer&lt;/title&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;h1&gt;WebServiceConsumer&lt;/h1&gt;<br />
&lt;p&gt;<br />
The web service returned: &lt;br /&gt;&lt;br /&gt;<br />
&lt;%= @service_output %&gt;<br />
&lt;/p&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</code></p>
<p>6.  Now fire up your WebServiceConsumer app on a different port</p>
<p>Depending on your particular setup this may be different.  I use lighttpd, so you&#8217;ll need to open app/config/lighttpd.conf and change the <code>server.port = 3000</code> to say something like <code>server.port = 3100</code>.  Then you can run <code>./script/server</code> to fire up your app on port 3100.</p>
<p>Now point your browser to http://localhost:3100/consumer</p>
<p>Enter your terms into the text box, click <strong>Subscribe</strong>, and pat yourself on the back.  You&#8217;ve just subscribed to a web service.</p>
]]></content:encoded>
			<wfw:commentRss>http://benrobb.com/2007/02/01/howto-put-wsdl-on-rails-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Howto: Make a Rails Environment in Ubuntu</title>
		<link>http://benrobb.com/2007/02/01/howto-make-a-rails-environment-in-ubuntu/</link>
		<comments>http://benrobb.com/2007/02/01/howto-make-a-rails-environment-in-ubuntu/#comments</comments>
		<pubDate>Thu, 01 Feb 2007 15:41:08 +0000</pubDate>
		<dc:creator>benrobb</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://benrobb.com/2007/02/01/howto-make-a-rails-environment-in-ubuntu/</guid>
		<description><![CDATA[In class today, there was a demonstration on how to get Apache/Axis/Tomcat running to demo some SOAP web services written in Java. As I plug Rails again, I was again amazed at the simplicity with which Rails handles all this. I began to think that there might be some interest in Rails web services for [...]]]></description>
			<content:encoded><![CDATA[<p>In class today, there was a demonstration on how to get Apache/Axis/Tomcat running to demo some SOAP web services written in Java.  As I plug Rails again, I was again amazed at the simplicity with which Rails handles all this.  I began to think that there might be some interest in Rails web services for those other members in my class, so in an attempt to help them out, I decided to provide instructions on setting up a Ruby on Rails environment.</p>
<p>Now I&#8217;m running mine inside a virtual machine with <a href="http://www.vmware.com/products/server/" title="vmware server">VMWare Server</a> on my Windows Server 2003 box.  I won&#8217;t get into all the reasons here, but these intructions would work for any VM or for a real install as a host operating system.  There are only one or two differences and I&#8217;ll point them out as we go along.</p>
<p><strong>1. Start with <a href="http://www.ubuntu.com/products/GetUbuntu/download#currentrelease" title="ubuntu server">Ubuntu Server</a> distro.</strong>  I&#8217;m using Ubuntu 6.10 Edgy Eft.<br />
Find the mirror you want, then click the Other Installation Options and find the server.  If you must have a graphical environment, you can get the desktop version, but know that youll have to install apache2 and mysql on your own.  If you choose the server option, you&#8217;ll be asked what kind of install you want to do.  Pick the LAMP option.  Do all appropriate setup, naming, networks, etc., and I&#8217;ll meet you again at the shell after you login.</p>
<p><strong>2. Edit your sources list.</strong></p>
<p><code>sudo vi /etc/apt/sources.list</code></p>
<p>Once you get inside, you&#8217;ll want to uncomment 4 lines, which will enable the universe repository along with the security universe repository.  I typically comment out the cdrom: repository as well.  For those unfamiliar with vi, the letter <strong>x</strong> will delete a single character.  Pushing the letter <strong>i</strong> will put you in insert mode to comment our the cdrom line.  Pushing <strong>Esc</strong> will get you out of edit mode. Pushing <strong>:</strong>, then <strong>wq</strong>, and finally <strong>Enter</strong> will put you back at shell with an edited sources list.</p>
<p><strong>3. Get SSH running</strong><br />
For me this is essential.  The interface through VMWare isn&#8217;t the speediest thing, and when you&#8217;re running over a Remote Desktop connection, things start to feel like molasses.  A few things will fix us right up, because through SSH everything runs beautifully.</p>
<p><code>sudo apt-get install openssh-server</code></p>
<p>This will install and start the SSH server.  Now you may need to configure port-forwarding through port 22 in order to connect to your Rails/Ubuntu server.  In addition if you need to forward traffic to your VM, then at your router point port 22 at the host OS and <a href="http://benrobb.com/2007/01/20/howto-port-forward-to-your-virtual-machine/" title="Port forwarding to a virtual machine">follow my other instructions</a> on port forwarding to a virtual machine.</p>
<p>If you&#8217;re happy where you&#8217;re at, then you can skip step 3.  If you want to do it, then SSH to your new server and continue to Step 4.</p>
<p><strong>4. Update all your packages</strong></p>
<p><code>sudo apt-get update<br />
sudo apt-get upgrade<br />
sudo apt-get install saidar</code></p>
<p>Saidar is optional, it&#8217;s a neat little monitoring utility that runs at the command line, but tells you about your CPU usage, memory usage, disk usage, and everything else you&#8217;d expect from your Task Manager or Activity Monitor.  Now it&#8217;s time to get down to business.</p>
<p><strong>5. Install Ruby</strong></p>
<p><code>sudo apt-get install ruby ruby1.8 ruby1.8-dev ri rdoc irb libmysql-ruby libmysqlclient15-dev</code></p>
<p>If you didn&#8217;t choose the LAMP option earlier (or picked a desktop distro) you&#8217;ll want to add Apache2 and mysql-server to this list:</p>
<p><code>sudo apt-get install ruby ruby1.8 ruby1.8-dev ri rdoc irb libmysql-ruby libmysqlclient15-dev apache2 mysql-server</code></p>
<p><strong>6.  Install RubyGems</strong><br />
RubyGems is like the apt-get utility for strictly Ruby packages.  This series of commands at the shell will download, install, and clean up the RubyGems package.</p>
<p><code>wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz<br />
tar -xvzf rubygems-0.9.0.tgz<br />
cd rubygems-0.9.0<br />
sudo ruby setup.rb<br />
cd ~<br />
rm -rf rubygems-0.9.0<br />
rm rubygems-0.9.0.tgz</code></p>
<p><strong>7. Install Rails</strong></p>
<p><code>sudo gem install rails --include-dependencies</code></p>
<p>This will show some errors while installing documentation, but never fear.  All is well.  We both know that you weren&#8217;t planning on reading the documentation anyway.</p>
<p><strong>8. Install Lighttpd with FastCGI</strong></p>
<p><code>sudo apt-get install lighttpd libfcgi-dev libfcgi-ruby1.8 build-essential<br />
</code></p>
<p>This will show an error that it tried to bind to port 80 and failed.  That&#8217;s ok, because we have apache running there.  What we&#8217;ve done is simply install it so that our Rails apps will use Lighttpd rather than the built-in WEBRick.</p>
<p>If like me you really just don&#8217;t like errors you can edit the lighttpd.conf file so that it binds to a different port.  This is not necessary at this point, but if you plan on running Rails apps in production you&#8217;ll have to play with the lighttpd config file at some point anyway.</p>
<p><code>vi /etc/lighttpd/lighttpd.conf</code></p>
<p>Find and uncomment the line that says</p>
<p><code># server.port = 81</code></p>
<p>Now we&#8217;ll run Stop just to make sure and then Start it up again.</p>
<p><code>sudo /etc/init.d/lighttpd stop<br />
sudo /etc/init.d/lighttpd start</code></p>
<p>Now install the fcgi RubyGem:</p>
<p><code>sudo gem install fcgi</code></p>
<p><strong>9. Make sure that your FastCGI bindings and MySQL bindings are working properly.</strong><br />
Now to make sure that our fastcgi and mysql libraries are working properly, we&#8217;ll fire up IRB.  IRB stands for Interactive Ruby.  It basically gives us a functional, yet empty ruby environment to play around.</p>
<p><code>irb<br />
irb(main):001:0&gt; require 'mysql'<br />
=&gt; true<br />
irb(main):002:0&gt; require 'fcgi'<br />
=&gt; true</code></p>
<p>Now, unless you want to do all your mysql configuration from the command line, you&#8217;ll need to be able to connect as root to your mysql database from a remote host.  See <a href="http://benrobb.com/2007/01/15/howto-remote-root-access-to-mysql/">my instructions</a> on how to do that.  You may need to set up port forwarding through port 3306 in order to get this to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://benrobb.com/2007/02/01/howto-make-a-rails-environment-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Howto: Put WSDL on Rails</title>
		<link>http://benrobb.com/2007/01/30/howto-put-wsdl-on-rails/</link>
		<comments>http://benrobb.com/2007/01/30/howto-put-wsdl-on-rails/#comments</comments>
		<pubDate>Wed, 31 Jan 2007 06:51:39 +0000</pubDate>
		<dc:creator>benrobb</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://benrobb.com/2007/01/30/howto-put-wsdl-on-rails/</guid>
		<description><![CDATA[Why do I love Rails so much? Because there is so much to love! Who ever dreamed that creating web services could be so simple? Where other frameworks can consume them very simply, Rails defines simplicity when it comes to creating them. Consuming them is easy as well, but it&#8217;s on the creation side that [...]]]></description>
			<content:encoded><![CDATA[<p>Why do I love Rails so much?  Because there is so much to love!  Who ever dreamed that creating web services could be so simple?  Where other frameworks can consume them very simply, Rails defines simplicity when it comes to creating them.  Consuming them is easy as well, but it&#8217;s on the creation side that Rails really stands out from the competition.  So how do you do it?</p>
<p>First off, let me say that my inexperience in web services means that I&#8217;m far from a subject matter expert.  I can however follow simple instructions, and I found a beautiful set over at the SOA Ranch.  This is a 3 part series, though more are supposedly coming.  I hope these articles continue to be published, but I have my doubts as the most recent articles are nearly 6 months old now.  The first one I found was <span style="text-decoration: line-through;">part 3</span> part 2.5 in the series, and you can follow the links back to part 1 &amp; part 2 (update 1/3/2009: I&#8217;ve removed the links since they no longer point to Rails content, apologies for the inconvenience).</p>
<p>So let&#8217;s get down to business.  I&#8217;ll make the assumption that you&#8217;ve got a <a title="how to make a working rails environment" href="http://benrobb.com/2007/02/01/howto-make-a-rails-environment-in-ubuntu/">working Rails environment</a>.  For Mac users, <a title="Locomotive" href="http://locomotive.raaum.org/">the latest version of Locomotive</a> has everything you need for creating web services.  For everyone else you&#8217;ll have to make your Rails environment the old fashioned way, although you can look forward to <a title="rubuntu" href="http://brainspl.at/articles/2006/02/16/rubuntu-is-almost-born">Rubuntu</a> soon.  We&#8217;re going to create a very simple web service that accepts a string, changes it a bit and returns a string.</p>
<p>First create yourself a new application</p>
<p><code>rails WebServiceProvider</code></p>
<p>Then you&#8217;ll want to open your application in your favorite Rails editor.  Then we need to generate your web service.</p>
<p><code>./script/generate web_service Manipulation manipulate</code></p>
<p>This will create an API file for us to define our web service&#8217;s interface.  It also creates a controller for us to use, and then a test file for us to use later (we won&#8217;t get to scripted testing in this article, although we will test it manually to prove that it works).</p>
<p>Now open up your manipulation_api.rb file in app/apis.  You&#8217;ll see the following line of code that is the beginnings of our string manipulating web service.</p>
<p><code>api_method :manipulate</code></p>
<p>We&#8217;ll need to define parameters and data types for our method like so:</p>
<p><code>api_method :manipulate, :expects =&gt; [:string], :returns =&gt; [:string]</code></p>
<p>There are many data types that can be used here, but we&#8217;re keeping things easy for now.  Now we&#8217;ll go look at the ManipulationController at app/controllers/manipulation_controller.rb.  Because we followed the standard Rails naming conventions the mapping of the web service to the controller is already done, but if we hadn&#8217;t, this mapping can be done explicitly by adding the following to our controller.</p>
<p><code>web_service_api ManipulationApi</code></p>
<p>We can also give our web service a different name with the wsdl_service_name directive</p>
<p><code>wsdl_service_name 'Manipulation'</code></p>
<p>Notice also that in the controller is where we define all our logic for what happens with the parameters being passed in by our web service consumer.  the manipulate method has already been created for us, so we simply need to tell our method to accept a string, perform our logic, and return another  string.</p>
<p>Again we&#8217;ll keep things simple.</p>
<p><code>def manipulate(terms)<br />
return "Yeah! " + terms + "!"<br />
end<br />
</code></p>
<p>Now for all intents and purposes, our web service has been coded.  We&#8217;ll add one more line to our controller that will generate a web front-end for the service so we can go see how it looks on the browser end.  Just add the following line to your controller.</p>
<p><code>web_service_scaffold :invoke</code></p>
<p>Now let&#8217;s turn on the server and see how things look.  Back at the terminal type</p>
<p><code>./script/server</code></p>
<p>Open your browser and point it to <a title="invoke web service" href="http://localhost:3000/Manipulation/invoke">http://localhost:3000/Manipulation/invoke</a>.  This shows us the web view of our API.  Follow the manipulate link to see the auto-generated web form that will show us what our service looks like.  Type your message into Param0 box and click the invoke button to see all your beautiful web service XML.  Another important point for those wishing to consume your web service is that Rails is automatically generating your wsdl for you.  You can see how this works by checking the routes.rb file in app/config but just know that visiting <a href="http://localhost:3000/Manipulation/service.wsdl">http://localhost:3000/Manipulation/service.wsdl</a> you can see the WSDL file that others will need to use your web service.  You can use something besides service.wsdl by editing your routes.rb file appropriately.</p>
<p>Now this is obviously a simple example, but it illustrates the basic steps and important points.  You probably wouldn&#8217;t have much use for a web service that adds the word &#8220;Yeah&#8221; and a few exclamation points to some user-input, but if we were doing this in the context of a real web application, you can start to imagine the possibilities available in your controller if you&#8217;ve got a dynamic database-driven application to work with.  You can add other methods to your API, define the param and return types there, then define the logic in the controller in the appropriate method.  Once you get the basics down, you&#8217;re on your way and the sky is the limit.  Good luck developing your first piece of the Web 2.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://benrobb.com/2007/01/30/howto-put-wsdl-on-rails/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Convert Line Breaks in Rails</title>
		<link>http://benrobb.com/2007/01/26/convert-line-breaks-in-rails/</link>
		<comments>http://benrobb.com/2007/01/26/convert-line-breaks-in-rails/#comments</comments>
		<pubDate>Fri, 26 Jan 2007 17:55:44 +0000</pubDate>
		<dc:creator>benrobb</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://benrobb.com/2007/01/26/convert-line-breaks-in-rails/</guid>
		<description><![CDATA[This may not be news to anyone else, but it was a surprise to me when I ran into it, so I thought perhaps someone else might find it helpful. Let&#8217;s imagine that you&#8217;ve got a form with a textarea that allows for a decent amount of user input, like, say a blog post or [...]]]></description>
			<content:encoded><![CDATA[<p>This may not be news to anyone else, but it was a surprise to me when I ran into it, so I thought perhaps someone else might find it helpful.  Let&#8217;s imagine that you&#8217;ve got a form with a textarea that allows for a decent amount of user input, like, say a blog post or a news item on your family website.</p>
<p>When you push the &#8220;Enter&#8221; key it goes down to the next line.  Behind the scenes, this is stored in your database as a new line character which is represented by &#8220;\n&#8221;.  The problem is that &#8220;\n&#8221; has no meaning to a web browser.  In web browser language, what you really need is a line break represented by the &#8220;&lt;br /&gt;&#8221; tag.  So how do you get all your new lines to turn into line breaks?  The answer is one simple method added to your application_helper.rb file in your Rails project.<br />
<code><br />
def line_break(string)<br />
&nbsp;&nbsp;&nbsp;&nbsp;string.gsub("\n", '&lt;br/&gt;')<br />
end<br />
</code></p>
<p>Then in your view, you simply call the line_break method around the appropriate block of text<br />
<code><br />
&lt;%= line_break(@news.body) %&gt;<br />
</code></p>
<p>and that&#8217;s all there is to it!</p>
]]></content:encoded>
			<wfw:commentRss>http://benrobb.com/2007/01/26/convert-line-breaks-in-rails/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Now Powered By Typo</title>
		<link>http://benrobb.com/2007/01/19/now-powered-by-typo/</link>
		<comments>http://benrobb.com/2007/01/19/now-powered-by-typo/#comments</comments>
		<pubDate>Fri, 19 Jan 2007 18:34:54 +0000</pubDate>
		<dc:creator>benrobb</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://benrobb.com/2007/01/19/now-powered-by-typo/</guid>
		<description><![CDATA[If you’ve been viewing my blog recently, you’ll now notice that the theme has changed and everything looks rather differently. There’s a good reason for this. I’ve now switched to Typo, a RubyOnRails powered blogging engine. I spent quite a bit of time evaluating a few different options, compared features, etc. I’ll post the results [...]]]></description>
			<content:encoded><![CDATA[<p>If you’ve been viewing my blog recently, you’ll now notice that the theme has changed and everything looks rather differently. There’s a good reason for this. I’ve now switched to Typo, a RubyOnRails powered blogging engine.</p>
<p>I spent quite a bit of time evaluating a few different options, compared features, etc. I’ll post the results of that later, because I figure it might save many other folks hours of work, but for now, the important things is that for me the benefits of switching outweighed sticking with WordPress. I’ve no complaints about WordPress, just love the extensibility of Rails and I know much more about Rails than I do about PHP. I even compared a few different Rails engines, but finally settled on Typo for many different reasons.</p>
<p>This is really my first real migration from a development environment to a production environment on a web-host. I’ve done a lot of the programming for other sites, but the migration was always handled by someone more experienced than I. So after struggling with cross-platform database migrations, Apache setup, .htaccess files, config files, and many another unforeseeable issue, I’m ready to declare this one a success.</p>
<p>As you poke around on the new site, you’ll probably notice a few strange looking things. “Double-quotes” and other things didn’t handle the migration as well, so it’ll take a little while to fix all those things, but it’ll get cleaned up before too long. For now, enjoy the new site.</p>
]]></content:encoded>
			<wfw:commentRss>http://benrobb.com/2007/01/19/now-powered-by-typo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Flash Helpers</title>
		<link>http://benrobb.com/2007/01/10/rails-flash-helpers/</link>
		<comments>http://benrobb.com/2007/01/10/rails-flash-helpers/#comments</comments>
		<pubDate>Wed, 10 Jan 2007 18:17:34 +0000</pubDate>
		<dc:creator>benrobb</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://benrobb.com/2007/01/10/rails-flash-helpers/</guid>
		<description><![CDATA[Rails allows for the posting of errors through use of flashes. Calling something like flash[:notice] = &#8220;Login Successful&#8221; in your controller will allow you to display it in your view by calling the following code in your view. The types of flashes you can use are not pre-defined so if you wanted to use flash[:pearl_jam] [...]]]></description>
			<content:encoded><![CDATA[<p>Rails allows for the posting of errors through use of flashes. Calling something like</p>
<p>flash[:notice] = &#8220;Login Successful&#8221;</p>
<p>in your controller will allow you to display it in your view by calling the following code in your view.</p>
<p><%= flash[:notice] %></p>
<p>The types of flashes you can use are not pre-defined so if you wanted to use</p>
<p>flash[:pearl_jam]</p>
<p>you could. That being said, there are some generally recognized types of flashes that folks are standardizing around. The most common flashes that I&#8217;ve seen are:</p>
<p>flash[:notice]<br />
flash[:message]<br />
flash[:warning]<br />
flash[:error]</p>
<p>I found some code at http://www.bigbold.com/snippets/posts/show/2348 that helped me out. You can edit it to suit your own needs. All you need to do is put thes code in your application_helper.rb file. It will allow you to call</p>
<p><%= display_standard_flashes %></p>
<p>in any of your views to display all flash types. This code also adds CSS class definitions that match the flash name, which will allow you to define a different look for your different flash types.</p>
]]></content:encoded>
			<wfw:commentRss>http://benrobb.com/2007/01/10/rails-flash-helpers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

