<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Rubynoob - Home</title>
  <id>tag:www.rubynoob.com,2008:mephisto/</id>
  <generator version="0.7.3" uri="http://mephistoblog.com">Mephisto Noh-Varr</generator>
  <link href="http://www.rubynoob.com/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://www.rubynoob.com/" rel="alternate" type="text/html"/>
  <updated>2007-07-12T03:43:57Z</updated>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>tad</name>
    </author>
    <id>tag:www.rubynoob.com,2007-07-12:361</id>
    <published>2007-07-12T03:43:00Z</published>
    <updated>2007-07-12T03:43:57Z</updated>
    <category term="HowTo"/>
    <category term="Ruby on Rails"/>
    <category term="forms. form_tag. form_remote_tag"/>
    <category term="howto"/>
    <category term="rails"/>
    <category term="rubyonrails"/>
    <category term="tutorial"/>
    <link href="http://www.rubynoob.com/articles/2007/7/12/forms-in-ruby-on-rails-part-2" rel="alternate" type="text/html"/>
    <title>Forms in Ruby on Rails - Part 2</title>
<summary type="html">&lt;p&gt;In the &lt;a href=&quot;http://www.rubynoob.com/articles/2007/7/9/forms-in-ruby-on-rails_part_1&quot;&gt;previous installment&lt;/a&gt;, we learned about two of Rails&#8217; methods that help create forms, form_for and remote_form_for.  Those methods dealt with forms primarily based on Model data.  Today we&#8217;ll turn our attention to form_tag and form_remote_tag which create more generic forms not tied to Model data.&lt;/p&gt;


	&lt;p&gt;Tutorial after the jump&#8230;&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;In the &lt;a href=&quot;http://www.rubynoob.com/articles/2007/7/9/forms-in-ruby-on-rails_part_1&quot;&gt;previous installment&lt;/a&gt;, we learned about two of Rails&#8217; methods that help create forms, form_for and remote_form_for.  Those methods dealt with forms primarily based on Model data.  Today we&#8217;ll turn our attention to form_tag and form_remote_tag which create more generic forms not tied to Model data.&lt;/p&gt;


	&lt;p&gt;Tutorial after the jump&#8230;&lt;/p&gt;
&lt;p&gt;As mentioned, form_tag allows you to create forms that aren&#8217;t tied to a particular Model in your Rails application.  In our super simple example, we&#8217;re going to have a form consisting of a single text input control and a submit button.  Whatever text is input will be displayed just below the form.&lt;/p&gt;


	&lt;p&gt;Here&#8217;s what our controller method looks like:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def form_tag_test
  @result = params[:text_to_display]
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;When called the first time the params array will be empty and @result will be nil.&lt;/p&gt;


	&lt;p&gt;Here&#8217;s our view:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Form_Tag Test&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;% form_tag( :action =&amp;gt; :form_tag_test ) do %&amp;gt;
      &amp;lt;%= text_field_tag( :text_to_display, @params[:text_to_display] ) %&amp;gt;
      &amp;lt;%= submit_tag( &amp;quot;Display Text!&amp;quot; ) %&amp;gt;
    &amp;lt;% end %&amp;gt;
    &amp;lt;strong&amp;gt;&amp;lt;%= @result %&amp;gt;&amp;lt;/strong&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Like the other form methods we&#8217;ve seen in rails, form_tag wraps code within in a ruby block, but in this case we&#8217;re not using a form_builder object.  Instead, we&#8217;ll use text_field_tag and its FormTagHelper ilk to build our form.  Our simple prototype only has a text_field_tag, but you can see documentation on all of your choices &lt;a href=&quot;http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;The second parameter of text_field_tag is the value in the params collection that the controller can find the entered value.  Each XX_field_tag method will send it&#8217;s value in a different hash key.  In this way, the controller will have access to every value in our form.&lt;/p&gt;


	&lt;p&gt;form_tag takes a parameter indicating which controller method to execute.  In our simple case we&#8217;re just going to call the same method again.  The documentation for &lt;a href=&quot;http://api.rubyonrails.org/classes/ActionController/Base.html#M000262&quot;&gt;url_for&lt;/a&gt; shows how to call other options on form_tag.&lt;/p&gt;


	&lt;p&gt;Our simple view concludes with a bit of ERb displaying the @result parameter.  When the page is first viewed, this parameter will be blank and nothing will be shown.&lt;/p&gt;


	&lt;p&gt;When we post the form, the form_tag_test method is called in the controller.  As we see in the code above, we read the value out of the params collection and put it into the @result variable.  Then, when the view is redisplayed, we see the value we entered into the text box in bold type just below our form.&lt;/p&gt;


	&lt;p&gt;form_remote_tag is the worst named of the lot.  If we have form_for and remote_form_for, why on earth don&#8217;t we also have remote_form_tag?  I suppose even Rails needs to contribute its own bit of perversity into the universe.  Of all the methods we&#8217;ve talked about so far, though, form_remote_tag is probably my favorite, since by definition it can do all kinds of fun &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; stuff and it isn&#8217;t tied to any model data.  We can use form_remote_tag for just about anything.&lt;/p&gt;


	&lt;p&gt;Here&#8217;s our form_remote_tag controller code:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def form_remote_tag_test
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;As you can see, all that it does is render the form_remote_tag_test.rhtml view:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Form_Remote_Tag Test&amp;lt;/title&amp;gt;
    &amp;lt;%= javascript_include_tag :defaults %&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;% form_remote_tag :url =&amp;gt; { :action =&amp;gt; :remote_test }, 
                       :update =&amp;gt; :results,
                       :complete =&amp;gt; visual_effect(:highlight, 'results') do %&amp;gt;
      &amp;lt;%= text_field_tag( :text_to_display, @params[:text_to_display] ) %&amp;gt;
      &amp;lt;%= submit_tag( &amp;quot;Display Text!&amp;quot; ) %&amp;gt;
    &amp;lt;% end %&amp;gt;
    &amp;lt;div id='results'&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This is a bit more interesting than the form_tag view.  First, notice that we&#8217;re including the default Rails javascripts up there in the head tag.  This is important, because without it &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; won&#8217;t work and you&#8217;ll usually get some weird output.  Also notice that besides the form_remote_tag method call, the rest of our form looks exactly the same.  The xx_field_tag methods work exactly the same as they did in form_tag, so we won&#8217;t mention them more here.&lt;/p&gt;


	&lt;p&gt;form_remote_tag looks a good bit like remote_form_for though.  In fact, the only real difference is that we don&#8217;t need to reference a Model object.  This time though we&#8217;re calling the remote_test method in the controller:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def remote_test
  @result = params[:text_to_display]
  render :partial =&amp;gt; 'form'
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Here we&#8217;re putting the text_to_display value from the params collection (which is the value entered into the text input control) into the @result variable and then we&#8217;re rendering the _form.rhtml partial.  In form_remote_tag we indicated that we wanted to :update the &lt;span class=&quot;caps&quot;&gt;DOM&lt;/span&gt; component called (with the id value of) :results.  So, the contents of the _form.rhtml partial goes into the results div.&lt;/p&gt;


	&lt;p&gt;Here&#8217;s the partial:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;%= @result %&amp;gt;&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;So, all we&#8217;re really doing is writing whatever is in the text box into the results div.  This would produce exactly the same result as the form_tag_test except for two things.  First, since we&#8217;re getting AJAXy with it, the browser doesn&#8217;t reload the page.  Second, the :complete =&amp;gt; visual_effect(:highlight, &#8216;results&#8217;) parameter makes the &#8216;results&#8217; div glow bright yellow and then fade back to white.  It&#8217;s a very simple &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; operation, but I think it illustrates the functionality pretty well.&lt;/p&gt;


	&lt;p&gt;Since I&#8217;ve been writing these tutorials and thinking about forms in Rails a good bit the past few days, the names have kind of grown on me.  Other than form_remote_tag they don&#8217;t seem too horribly named.  I now think of form_for as meaning &#8220;make a form &lt;em&gt;for&lt;/em&gt; this particular Model object.&#8221;  form_tag now seems pretty obvious &#8211; it creates an html form tag.  Perhaps it&#8217;s just the lack of clear documentation that lead to my confusion.&lt;/p&gt;


	&lt;p&gt;My lesson, and maybe yours as well, to learn out of this is that when something is confusing, even if it&#8217;s something you&#8217;ve been using for a while, it is probably a good idea to break it down into a very simple working prototype.  Then you may be able to grasp how it works, why it works, and maybe why the heck it&#8217;s named the way it is.&lt;/p&gt;


	&lt;p&gt;As always, thanks for reading, and please leave a comment if you have any questions at all.  I&#8217;m no expert, but I&#8217;ll be glad to try to help.  Please feel free as well to point out any errors I&#8217;ve made or rewrite sections of code that may need it.&lt;/p&gt;


	&lt;p&gt;I think my next topic will be how to integrate Google Checkout into your Ruby on Rails application.  Hope to have it up soon!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>tad</name>
    </author>
    <id>tag:www.rubynoob.com,2007-07-09:344</id>
    <published>2007-07-09T05:15:00Z</published>
    <updated>2007-07-09T05:37:37Z</updated>
    <category term="HowTo"/>
    <category term="Ruby on Rails"/>
    <category term="rails rubyonrails forms form"/>
    <link href="http://www.rubynoob.com/articles/2007/7/9/forms-in-ruby-on-rails_part_1" rel="alternate" type="text/html"/>
    <title>Forms in Ruby on Rails - Part 1</title>
<summary type="html">&lt;p&gt;I was confused for a pretty long time about how to create forms in Ruby on Rails.  Since many (most?) Rails applications are tied to databases, it makes sense that many interactions with model data will be done via &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; forms.  My problem though, was that there just seemed to be too many choices, and the choices are poorly named.&lt;/p&gt;


	&lt;p&gt;Tutorial after the jump&#8230;&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;I was confused for a pretty long time about how to create forms in Ruby on Rails.  Since many (most?) Rails applications are tied to databases, it makes sense that many interactions with model data will be done via &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; forms.  My problem though, was that there just seemed to be too many choices, and the choices are poorly named.&lt;/p&gt;


	&lt;p&gt;Tutorial after the jump&#8230;&lt;/p&gt;
&lt;p&gt;There are four Rails methods to use when we create forms.  We can chose from the following:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;form_for&lt;/li&gt;
		&lt;li&gt;remote_form_for&lt;/li&gt;
		&lt;li&gt;form_tag&lt;/li&gt;
		&lt;li&gt;form_remote_tag&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;To my mind, none of these methods really indicate what they do or how to use them.  The &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; documentation doesn&#8217;t really help either &#8211; at least not in really knowing how to use these methods.  It makes sense that the remote methods deal with &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; but I still can&#8217;t tell by looking what they do.&lt;/p&gt;


	&lt;p&gt;So now let&#8217;s go over the basics of each method and how and when to use them.  We&#8217;re only going to cover the basics since you can get pretty fancy with each.  Hopefully, though, if you can understand this article, you can use that as a springboard into figuring out the more advanced stuff.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Here&#8217;s the most important morcel of this tutorial&lt;/strong&gt;.  &lt;em&gt;form_for&lt;/em&gt; and &lt;em&gt;remote_form_for&lt;/em&gt; are both methods to use when you want to present model based data.  &lt;em&gt;form_tag&lt;/em&gt; and &lt;em&gt;form_remote_tag&lt;/em&gt; are more general purpose methods which are not based on a model&#8217;s data.&lt;/p&gt;


	&lt;p&gt;form_for allows you to create forms based on the models you&#8217;ve created for your Rails app.  Let&#8217;s say that we have a model named &#8216;Visitor&#8217; tied to a database table, visitors, which contains a field named &#8216;avatar_name&#8217;.  Our controller method that we&#8217;ll use to test form_for can look like this:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def form_for_test
  @visitor = Visitor.find_first
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;So here we&#8217;re just grabbing the first row in the visitors table and putting it into the @visitor variable which will be accessible in the form_for_test.rhtml view.  Here&#8217;s the view:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Form_For Tester&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;% form_for :visitor, :url =&amp;gt; { :action =&amp;gt; 'save', :id =&amp;gt; @visitor } do |f| %&amp;gt;
      Avatar Name: &amp;lt;%= f.text_field :avatar_name %&amp;gt;
      &amp;lt;%= submit_tag 'Save' %&amp;gt;
    &amp;lt;% end %&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/hmtl&amp;gt;&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This is a really trivial form, but I think it illustrates the basic concept.  form_for&#8217;s first variable is the let&#8217;s the form know that it will be using the variable @visitor that we created up in the controller.  The :url hash tells us which method on the controller we&#8217;ll execute when the submit button is pushed, and the :id parameter allows the controller to pull out the id of the visitor model from the params collection which we&#8217;ll see in a moment.&lt;/p&gt;


	&lt;p&gt;form_for&#8217;s contents reside within a ruby block which we see in the &#8216;do |f|&#8217; bit.  Since we&#8217;re in the block, we can make calls against the &#8216;f&#8217; variable, which is defined as a &#8216;form_builder&#8217; object.  This gives us access to methods to define every sort of form element.  In this simple example, we&#8217;re putting the avatar_name column value into a text_field which maps to an input control.  You can see the &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; document for every other type of control &lt;a href=&quot;http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Here&#8217;s the &#8216;save&#8217; method which gets called when we submit the form:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def save
  visitor = Visitor.find(params[:id])
  visitor.update_attributes(params[:visitor])
  redirect_to :action =&amp;gt; 'form_for_test'
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This is a really trivial and simple implementation, but it gets the job done.  First we find the visitor we&#8217;re updating from the database.  We do this by grabbing the :id parameter (which we allowed for with &#8217;:id =&amp;gt; @visitor&#8217; back in the view).  Next we use some Rails magic.  update_attributes grabs the visitor parameter representing the changes we made when we submitted the form and applies them to the model object and saves it to the database.  In any rails app beyond a simple learning tool we&#8217;d use the fact that update_attributes returns false on failure to handle any errors.&lt;/p&gt;


	&lt;p&gt;Finally in our simple app we just redirect back to the page we came from.  I&#8217;d probably rather go to a success page or give the user some indication that the save was successful.  We&#8217;ll do that now with remote_form_for which allows AJAXy form posting.&lt;/p&gt;


	&lt;p&gt;Our controller method for our remote_form_for test page looks familiar:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def remote_form_for_test
  @visitor = Visitor.find_first
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Just the same as the form_for controller method.&lt;/p&gt;


	&lt;p&gt;The view, however, looks a little different:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Remote_Form_For Tester&amp;lt;/title&amp;gt;
    &amp;lt;%= javascript_include_tag :defaults %&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;% remote_form_for :visitor, @visitor, 
                       :url =&amp;gt; { :action =&amp;gt; 'save_remote', :id =&amp;gt; @visitor },
                       :update =&amp;gt; 'result',
                       :complete =&amp;gt; visual_effect(:highlight, 'result') do |f| %&amp;gt;
      Avatar Name: &amp;lt;%= f.text_field :avatar_name %&amp;gt;
      &amp;lt;%= submit_tag 'Save' %&amp;gt;
    &amp;lt;% end %&amp;gt;
    &amp;lt;div id='result'&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/hmtl&amp;gt;&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;remote_form_for works exactly like form_for except we add in support for &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt;.  So, we need to add the javascript_include_tag method into our head element.  Also, note the additional :update and :complete parameters.  :update indicates that after we post the form, we are going to do something with the &#8216;result&#8217; div.  :complete says that after the form has been successfully posted we&#8217;re going to do a scriptaculous highlight effect on whatever is in the &#8216;results&#8217; div.&lt;/p&gt;


	&lt;p&gt;The possible &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; parameters we can pass to remote_form_for are explained in the &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; documentation for the link_to_remote method which you can find &lt;a href=&quot;http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M000527&quot;&gt;here&lt;/a&gt;.  You can find documentation for using scriptaculous effects with visual_effect &lt;a href=&quot;http://api.rubyonrails.org/classes/ActionView/Helpers/ScriptaculousHelper.html#M000515&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;When the form posts we&#8217;re going to asynchronously call the &#8216;save_remote&#8217; method in the controller.  Here&#8217;s what it looks like:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def save_remote
  visitor = Visitor.find(params[:id])
  visitor.update_attributes(params[:visitor])
  @result = 'Saved!'
  render :partial =&amp;gt; 'form'
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The first two lines of this method are the same as the form_for save method we discussed earlier.  We&#8217;ve added in a @result variable and given it a message about our assumed success.  Then we render the _form.rhtml partial which will fit into the &#8216;results&#8217; div as per the :update parameter in the remote_form_for method back in the view.&lt;/p&gt;


	&lt;p&gt;The _form.rhtml partial is stupidly simple:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;%= @result %&amp;gt;&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;So, we&#8217;re just putting &#8216;Saved!&#8217; at the bottom of the form after the form is posted.  Since this is done in an &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; manner, the browser doesn&#8217;t load a new page, it just displays the result partial and then immediately performs a scriptaculous highlight effect which turns the div bright yellow and then slowly fades it back to normal.&lt;/p&gt;


	&lt;p&gt;We could also add a spinning graphic if the process took a while to let users know something is going on.  We could have the results div slide down or fade in or perform all sorts of other effects.&lt;/p&gt;


	&lt;p&gt;That&#8217;s it for a quick run-down on form_for and remote_form_for.  I&#8217;m still not really sure why those names were chosen.  model_form might have made more sense.  In the next couple of days I&#8217;ll conclude this series with a discussion of the more versatile yet even more confusingly named form_tag and form_remote_tag methods.&lt;/p&gt;


	&lt;p&gt;As usual, if I&#8217;ve made a mistake or if you know a better way to do something, please leave a comment.  Similarly, if you&#8217;re having a problem with forms in Ruby on Rails, please leave a comment and ask.  I&#8217;m no expert, but I&#8217;ll do my best to help.  Thanks for reading!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>tad</name>
    </author>
    <id>tag:www.rubynoob.com,2007-06-28:309</id>
    <published>2007-06-28T20:05:00Z</published>
    <updated>2007-06-28T22:43:20Z</updated>
    <category term="Ruby on Rails"/>
    <category term="RubyNoob"/>
    <category term="Typo"/>
    <category term="dreamhost"/>
    <category term="mephisto"/>
    <category term="rails"/>
    <category term="ruby"/>
    <category term="rubynoob"/>
    <category term="slicehost"/>
    <category term="typo"/>
    <link href="http://www.rubynoob.com/articles/2007/6/28/rubynoob-reborn" rel="alternate" type="text/html"/>
    <title>RubyNoob Reborn!</title>
<content type="html">
            &lt;p&gt;After months and months of neglect, primarily due to the fact that I&#8217;ve had tons of problems getting &lt;a href=&quot;http://trac.typosphere.org/&quot;&gt;Typo&lt;/a&gt; to run properly on &lt;a href=&quot;http://www.dreamhost.com/&quot;&gt;Dreamhost&lt;/a&gt;, I have finally revived RubyNoob running in &lt;a href=&quot;http://mephistoblog.com/&quot;&gt;Mephisto&lt;/a&gt;!  RubyNoob is up and running on a slice from &lt;a href=&quot;http://www.slicehost.com/&quot;&gt;SliceHost&lt;/a&gt;, being served by &lt;a href=&quot;http://litespeedtech.com/&quot;&gt;Litespeed&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;I&#8217;m planning on writing up some guides on how I did the transition from Typo and Dreamhost to Mephisto and Slicehost, but first I&#8217;d like to thank Paul over at &lt;a href=&quot;http://www.usefuljaja.com/&quot;&gt;UsefulJaja&lt;/a&gt; for creating the &lt;a href=&quot;http://www.usefuljaja.com/debian-vps&quot;&gt;incredible tutorials&lt;/a&gt; that I followed in setting up my new slice.&lt;/p&gt;


	&lt;p&gt;As I&#8217;m writing this, the new RubyNoob is using the plain generic Mephisto theme.  I&#8217;m planning on slowly evolving my own theme over the next few months.  I&#8217;m hardly a web designer or expert in &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt;, but it&#8217;s time that I learn and what I&#8217;d like to do isn&#8217;t really anything spectacular or complicated.&lt;/p&gt;


	&lt;p&gt;Since my last useful posts I&#8217;ve learned a &lt;strong&gt;lot&lt;/strong&gt; of stuff about Ruby on Rails.  I&#8217;ve added a full e-commerce solution to &lt;a href=&quot;http://www.joyli.net&quot;&gt;JoyLi.net&lt;/a&gt; by integrating it with &lt;a href=&quot;http://www.google.com/checkout&quot;&gt;Google Checkout&lt;/a&gt;.  That was a great experience and I&#8217;ll be writing about that as well.&lt;/p&gt;


	&lt;p&gt;If you&#8217;re reading this, you&#8217;ve found your way to the new RubyNoob (or your &lt;span class=&quot;caps&quot;&gt;RSS&lt;/span&gt; subscription actually figured out what happened and I&#8217;m amazed) and I&#8217;d like to thank you for stopping by.  Let&#8217;s hope I keep the ball rolling from here on out!&lt;/p&gt;


	&lt;p&gt;Note: all comments since the migration have been given the date of the migration, sometime in June 2007.  Please ignore all the comment dates.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>TDonaghe</name>
    </author>
    <id>tag:www.rubynoob.com,2007-01-24:49</id>
    <published>2007-01-24T13:05:00Z</published>
    <updated>2007-06-25T20:23:51Z</updated>
    <category term="Ruby on Rails"/>
    <category term="RubyNoob"/>
    <category term="Typo"/>
    <category term="dreamhost"/>
    <category term="rubynoob"/>
    <category term="typo"/>
    <link href="http://www.rubynoob.com/articles/2007/1/24/rails-errors-fastgi-bad" rel="alternate" type="text/html"/>
    <title>Rails + Errors + FastGI == Bad</title>
<content type="html">
            &lt;p&gt;One way to generate a lot of &#8220;500 &#8211; Application Failed&#8221; errors in Ruby on Rails applications running on Dreamhost is by throwing a lot of errors.  Right now my newly downloaded Typo (supposedly the most recent stable version) is throwing some errors and this is, in part, causing RubyNoob to keep going down.&lt;/p&gt;


	&lt;p&gt;I&#8217;m investigating this to see what I can figure out.  My advice is, if you&#8217;re running Rails on Dreamhost and you keep getting application failure errors, the first place to look is your production.log file.  Make sure to clear up all errors first.&lt;/p&gt;


	&lt;p&gt;I&#8217;ll talk about what else you can do once I get RubyNoob a bit more stable.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>TDonaghe</name>
    </author>
    <id>tag:www.rubynoob.com,2007-01-24:47</id>
    <published>2007-01-24T09:05:00Z</published>
    <updated>2007-07-11T19:24:51Z</updated>
    <category term="HowTo"/>
    <category term="Ruby on Rails"/>
    <category term="RubyNoob"/>
    <category term="rails"/>
    <category term="windows"/>
    <link href="http://www.rubynoob.com/articles/2007/1/24/windows-is-evil" rel="alternate" type="text/html"/>
    <title>Windows is Evil</title>
<content type="html">
            &lt;p&gt;Simple lesson for other Ruby on Rails noobs &#8211; editting dispatch.fcgi in Windows and then uploading to your website may be hazardous for your site!!&lt;/p&gt;


	&lt;p&gt;Although I haven&#8217;t had other issues with doing so, after totally destroying RubyNoob over the past few days, I&#8217;m always going to do any editting of dispatch.fcgi through my Dreamhost shell!  Apparently some invisible characters can get into your file and keep your site from starting up.&lt;/p&gt;


	&lt;p&gt;I&#8217;ve also updated to the latest and greatest typo, but in the process I&#8217;ve lost the comments for the 4 or 5 most recent posts &#8211; and that sucks.  I&#8217;ll see what I can do to resurrect them &#8211; or at least the ones worth bringing back.&lt;/p&gt;


	&lt;p&gt;I have an interesting article coming soon about Dreamhost and Ruby on Rails and Applications failing to start.  I&#8217;m going to try to make the changes I&#8217;ll be mentioning and we&#8217;ll see if RubyNoob becomes more stable.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>TDonaghe</name>
    </author>
    <id>tag:www.rubynoob.com,2007-01-23:48</id>
    <published>2007-01-23T20:33:00Z</published>
    <updated>2007-07-11T19:25:06Z</updated>
    <category term="joyli"/>
    <category term="jquery"/>
    <category term="rails"/>
    <category term="rubyonrails"/>
    <category term="thickbox"/>
    <link href="http://www.rubynoob.com/articles/2007/1/23/introducing-joyli-net" rel="alternate" type="text/html"/>
    <title>Introducing JoyLi.Net</title>
<content type="html">
            &lt;p&gt;In conjunction with my wife Lindsay, and our development company, Blue Cockatoo Creative (website in progress), we&#8217;re proud to annouce the release of our first, full-fledged Ruby On Rails website, &lt;a href=&quot;http://www.joyli.net&quot;&gt;JoyLi.net&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;a href=&quot;http://www.macrolinz.com&quot;&gt;Lindsay&lt;/a&gt; created the graphics and the general web design, while I stitched the pages together, created the database and did general rails magic.  There&#8217;s no real Ajax on the site, though we did include a bit of groovy javascript.&lt;/p&gt;


	&lt;p&gt;Lindsay talked me into using &lt;a href=&quot;jquery.com/demo/thickbox/&quot;&gt;ThickBox&lt;/a&gt;  and &lt;a href=&quot;http://www.jquery.com&quot;&gt;JQuery&lt;/a&gt; instead of the standard Prototype and Scriptaculous libraries which have built-in support in Rails.  Her argument was that we&#8217;d save time by not forcing users to download those other libraries and I relented, though after we finished I think we both agreed to just use what ships with Rails in the future.  If someone goes ahead and fully integrates JQuery into rails, though, we&#8217;d stick with it.&lt;/p&gt;


	&lt;p&gt;Here&#8217;s a couple of teaser images:&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://rubynoob.qiaza.com/assets/2007/6/25/home.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://rubynoob.qiaza.com/assets/2007/6/25/collections.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;


	&lt;p&gt;JoyLi.net took us about 90 hours worth of total effort.  It uses mysql and is currently running on FastCGI on Dreamhost.  So far we don&#8217;t seem to be experiencing the horrible 500 errors that many people get with Dreamhost.  I think I may have found a solution to those problems, and I&#8217;ll blog about that soon.&lt;/p&gt;


	&lt;p&gt;For fun, watch the home page for more than 15 seconds or so.  Javascript is fun!&lt;/p&gt;


	&lt;p&gt;Please leave a comment and let me know what you think!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>TDonaghe</name>
    </author>
    <id>tag:www.rubynoob.com,2006-09-22:46</id>
    <published>2006-09-22T06:29:00Z</published>
    <updated>2007-06-11T02:51:47Z</updated>
    <link href="http://www.rubynoob.com/articles/2006/9/22/how-to-deploy-your-first-rails-app-to-dreamhost-using-capistrano-in-windows" rel="alternate" type="text/html"/>
    <title>How To Deploy your first rails app to Dreamhost using Capistrano in Windows</title>
<summary type="html">&lt;p&gt;Credit: This tutorial owes its existence to the wonderful Dreamhost/Capistrano &lt;a href=&quot;http://wiki.dreamhost.com/index.php/Capistrano&quot;&gt;wiki article&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;The primary thrust of this tutorial will be to help you deploy your first rails app using Capistrano from a Windows environment.  Although I&#8217;m specifically addressing deploying to Dreamhost, you may be able to modify things to work with your own host.  Rails apps on Dreamhost usually run on Fast-CGI, so this tutorial covers that as well.  You may need to find more information in order to get your app up and running on Lighttpd or Mongrel.&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;Credit: This tutorial owes its existence to the wonderful Dreamhost/Capistrano &lt;a href=&quot;http://wiki.dreamhost.com/index.php/Capistrano&quot;&gt;wiki article&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;The primary thrust of this tutorial will be to help you deploy your first rails app using Capistrano from a Windows environment.  Although I&#8217;m specifically addressing deploying to Dreamhost, you may be able to modify things to work with your own host.  Rails apps on Dreamhost usually run on Fast-CGI, so this tutorial covers that as well.  You may need to find more information in order to get your app up and running on Lighttpd or Mongrel.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;UPDATE&lt;/span&gt;:  Thanks to Chris_M from the comments for letting me in on another preperatory step.  Before using Capistrano, please download the subversion command line stuff from &lt;a href=&quot;http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;You&#8217;re also going to want to be doing this using the &lt;a href=&quot;http://wiki.rubyonrails.org/rails/pages/EdgeRails/versions/88&quot;&gt;latest edge version of Rails&lt;/a&gt;.  If you&#8217;re reading this after Rails 1.2 is available, you may not need edge.&lt;/p&gt;


First, let&#8217;s install capistrano:
&lt;pre&gt;&lt;code&gt;
     gem install capistrano
&lt;/code&gt;&lt;/pre&gt;

The next thing you&#8217;ll need to do is to set up a simple rails app.  Create a rails app:
&lt;pre&gt;&lt;code&gt;
     rails CapTest
&lt;/code&gt;&lt;/pre&gt;

Now, in order to play with Capistrano to see if your deployment works, our app will just display an index.rhtml page.  First let&#8217;s create a controller:
&lt;pre&gt;&lt;code&gt;
     script/generate controller whatever
&lt;/code&gt;&lt;/pre&gt;
Now create an index.rthml file under app/views/whatever.  Let&#8217;s just make it look like this:

&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;ta&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;ta&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;ta&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;CAPTest&lt;span class=&quot;ta&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;ta&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;ta&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;ta&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      It is now &lt;span class=&quot;c&quot;&gt;&amp;lt;%= Time.now %&amp;gt;&lt;/span&gt;. &lt;span class=&quot;ta&quot;&gt;&amp;lt;br&lt;/span&gt; &lt;span class=&quot;ta&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;      &lt;span class=&quot;ta&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    &lt;span class=&quot;ta&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;ta&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


	&lt;p&gt;In this way, we can make sure that rails is running.  Once we get the app up to Dreamhost and running, we&#8217;ll add another couple of lines to this simple file as we deploy a few times to see the Capistrano magic.&lt;/p&gt;


	&lt;p&gt;We&#8217;re almost done with setup.  Now, let&#8217;s change our route so that when we visit our site we&#8217;ll go straight to our test page.  Open config/routes.rb and make sure it has a line like this:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
    map.connect '', :controller =&gt; &quot;whatever&quot; 
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;In order to get the whatever controller&#8217;s index page to work like this, though, you need to delete the index.rhtml found in your app&#8217;s public folder.&lt;/p&gt;


	&lt;p&gt;Now, let&#8217;s test the app with a WEBrick/Mongrel (depending on your version of Rails) server.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
    ruby script/server
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Just go to http://localhost:3000/ in your browser and you should see our test page showing the current time.  Now, over to Dreamhost.&lt;/p&gt;


	&lt;p&gt;Our next step will be to set up a Subversion repository on Dreamhost and get our CapTest application into it.  This is a very important step; we won&#8217;t be able to utilize Capistrano without it.  So, go look at my handy-dandy Windows+Subversion+Tortoise+Dreamhost tutorial and come back when you get stuff set up.&lt;/p&gt;


	&lt;p&gt;Ok, now you should have a CapTest rails app that&#8217;s synched up with a subversion repository up at Dreamhost.  Take a look at your app in explorer:&lt;br /&gt;&lt;/p&gt;


	&lt;p&gt;&lt;img src=&quot;http://icuo.us/images/capistrano1.png&quot; alt=&quot;&quot; /&gt;    &lt;br /&gt;&lt;/p&gt;


	&lt;p&gt;All of your folders should have green check marks like mine.  If any don&#8217;t, right click on the topmost folder and choose &lt;span class=&quot;caps&quot;&gt;SVN&lt;/span&gt; Commit&#8230; That will allow you to resynch whatever&#8217;s out of synch.&lt;/p&gt;


	&lt;p&gt;Now let&#8217;s create a subdomain to stick all this stuff up at Dreamhost.  Just go into Manage Domains and create a new subdomain (something like captest.yourdomainname.com) and make sure that the FastCGI open is checked and be sure to append /current/public, instead of the default directory suggested.  &lt;span class=&quot;caps&quot;&gt;IMPORTANT&lt;/span&gt;: After &lt;span class=&quot;caps&quot;&gt;DNS&lt;/span&gt; allows access to your newapp.yourdomain.com/current/public folder, you must manually delete the &#8221;/current/public&#8221; that DH creates. This is so that later in this tutuorial, &#8216;cap deploy&#8217; can create a symlink to /current, allowing capistrano and subversion to live happily together. Thanks to topfunky.com for the troubleshooting tip!&lt;/p&gt;


	&lt;p&gt;The next step is to modify your app according to the instructions under the config/environment section of the Capistrano/Dreamhost tutorial.  When you deploy your app it needs to be in Production mode already.  One strategy for managing your development work vs the production files is to synch up the important production files first and then modify them for development work &#8211; just remember to not synch the development versions!  There&#8217;s probably a better way to handle this that I haven&#8217;t thought of.  If you know a better strategy, please leave a comment below.&lt;/p&gt;


	&lt;p&gt;Now can we start playing with Capistrano.  First, let&#8217;s Capistranoize our application.  Open a command window at the toplevel of your app and type:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
    cap --apply-to .
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;This will create two files in your app.  A config/deploy.rb and a lib/tasks/capistrano.rake.  Use tortoise to synch them up with your repository.&lt;/p&gt;


	&lt;p&gt;The next step is to modify your deploy.rb file.  This file contains the bits of information that are specific to your app and your host.  Getting all of this to work properly has been difficult for me, I think primarily because I&#8217;m deploying from Windows.  Let&#8217;s look at my deploy.rb file.  You&#8217;ll need to change a few things to make it particular to your domain and sub-domain.  The comments up to where the Tasks start should be self-explanatory.  This is all standard capistrano deployment for Dreamhost accounts.  We&#8217;ll discuss the tasks below.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
    # the name of your subversion application
    set :application, &quot;captest&quot; 
    # use exactly what you see on the Dreamhost subversion control panel
    set :repository, &quot;http://www.icuo.us/captest&quot; 

    # These three should be set to your subdomain name you set up
    # on Dreamhost.  The explanation of all of these is beyond 
    # the scope of this tutorial.
    role :web, &quot;cap.icuo.us&quot; 
    role :app, &quot;cap.icuo.us&quot; 
    role :db,  &quot;cap.icuo.us&quot;, :primary =&gt; true

    # This is the directory you created when you setup
    # your subdomain on Dreamhost.  Don't include the
    # public/current part...
    set :deploy_to, &quot;/home/tdonaghe/cap.icuo.us&quot; 

    # Dreamhost doesn't allow you to use sudo.
    set :use_sudo, false

    # Do this so subversion doesn't create a .svn in your
    # world-accessible directory.
    set :checkout, &quot;export&quot; 

    # Make sure to set this to your DreamHost user name that
    # you use when you connect to ssh
    set :user, &quot;your_user_name&quot; 

    #      
    # TASKS
    # 
    desc &quot;Tasks to execute after code update&quot; 
    task :after_update_code, :roles =&gt; [:app, :db, :web] do
     # fix permissions
     run &quot;chmod +x #{release_path}/script/process/reaper&quot; 
     run &quot;chmod +x #{release_path}/script/process/spawner&quot; 
     run &quot;chmod 755 #{release_path}/public/dispatch.*&quot; 
    end

    desc &quot;Restarting after deployment&quot; 
    task :after_deploy, :roles =&gt; [:app, :db, :web] do
     run &quot;touch /home/tdonaghe/cap.icuo.us/current/public/dispatch.fcgi&quot; 
    end

    desc &quot;Restarting after rollback&quot; 
    task :after_rollback, :roles =&gt; [:app, :db, :web] do
     run &quot;touch /home/tdonaghe/cap.icuo.us/current/public/dispatch.fcgi&quot; 
    end
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;During my initial experimentations with Capistrano, I would have a lot of failures when deploying.  These failures all stemmed around the executable permissions of the reaper and spawner scripts.  I think this is a problem because when you build your rails app in Windows, you don&#8217;t have a good way to set the unix style permissions on these files.  The first task takes care of this.&lt;/p&gt;


	&lt;p&gt;This task is called :after_update_code.  Capistrano runs various tasks while it&#8217;s deploying your code.  For each of these tasks you can create custom tasks to run either before or after they run.  Just create a new task with the prefix of either &#8220;before&#8221; or &#8220;after&#8221; and the task name you&#8217;d like to add behavior to.  In the :after_update_code case we&#8217;re going to run some unix commands after all of the code has been deployed onto the server.&lt;/p&gt;


	&lt;p&gt;When Capistrano deploys your app, it creates a directory structure something like this:
&lt;img src=&quot;http://icuo.us/images/capistrano2.png&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;&lt;/p&gt;


	&lt;p&gt;To get this started, let&#8217;s save this deploy.rb file as is and commit it to your subversion repository.  Now, in a command line, run &#8220;cap setup&#8221; in a command window from the top level of your rails app.  This will create the necessary starting structure up on the server for your app to be deployed to.&lt;/p&gt;


	&lt;p&gt;The important thing to notice in the :after_update_code is that your code goes into a 2006XXXX directory under the subdomain/releases directory.  The location of this directory is stored in the release_path variable, and that&#8217;s what&#8217;s used in the after_update_code task.  After the deploy step, Capistrano sets a symlink to point our cap.icuo.us/current/public directory to whatever the most recent release/public directory is.  After the code update that&#8217;s not set yet, so we have to refer to the most recent release path as you see in the :after_update_code task.&lt;/p&gt;


	&lt;p&gt;So, we set executable permissions on the two process scripts as well as chmod&#8217;ing public/dispatch.* to 755 &#8211; something else I don&#8217;t know how to do in Windows.&lt;/p&gt;


	&lt;p&gt;Finally, there&#8217;s one more step for the deploy process &#8211; yet another stepped I figured out through trial and error.  At the end of the deploy process you can see the reaper script attempt to restart the server by calling dispatch.fcgi.  As you can see, this step fails:
&lt;img src=&quot;http://icuo.us/images/capistrano3.png&quot; alt=&quot;&quot; /&gt;    &lt;br /&gt;&lt;/p&gt;


	&lt;p&gt;If we let the deployment stop at this point, our web app won&#8217;t start and we&#8217;ll get a Rails error.  I found that if I ssh&#8217;d into Dreamhost and opened dispatch.fcgi in nano, made a trivial edit (I think just stick a space after a comment) and then save that I could refresh the webpage and the app would work.  I couldn&#8217;t though, figure out how to script in calling nano into a task.  I finally remembered reading that you could sometimes &#8220;touch dispatch.fcgi&#8221; to get it to run sometimes.  So, I created the :after_deploy task to do exactly that.&lt;/p&gt;


	&lt;p&gt;With the :after_update_code and :after_deploy tasks in place, you should be able to save your deploy.rb file, commit it to your subversion repository, and then run &#8220;cap deploy&#8221; in a command window from the top level directory of your rails app.  If everything works ok you&#8217;ll soon be prompted to enter your ssh password.  Then more scripts will run, and hopefully the process will end with no errors.&lt;/p&gt;


	&lt;p&gt;If you get errors at this point, please leave me a comment and I&#8217;ll try to help you out, and hopefully more knowledgeable folks will help as well.  If you&#8217;re deploying this really simple rails app from Windows to Dreamhost we ought to be able to figure something out.  The first thing I&#8217;d check is your dispatch.fcgi file.  Open it in a text editor like Notepad++ and look at the end-of-line characters.  If you have anything other than just LineFeeds (LF) at the end of each line, you&#8217;ll need to convert the file to Unix format, commit the file to your repository and try again.&lt;/p&gt;


	&lt;p&gt;Now try to navigate to your website.  If it fails, see the previous paragraph.  Let&#8217;s be optimistic and assume that everything works ok.  Now let&#8217;s witness the power of Capistrano!  Go into your app/views/whatever folder and edit your index.rhtml file.  Just add a line to the end of it.  Now save and commit the file to subversion.  Run &#8220;cap deploy&#8221; again.  Refresh your webpage.  Voila!  You should see your new line!&lt;/p&gt;


	&lt;p&gt;Now, let&#8217;s try a different Capistrano method.  In your deploy.rb file you should also have a task that runs after a rollback, :after_rollback.  This guy just &#8220;touches&#8221; your dispatch.fcgi file again.  This time we can&#8217;t use #{release_path} to get to the public folder because by this time, that&#8217;s gone.  So, we just use the absolute path of your newly rolled back app.  Let&#8217;s try it out.  Do &#8220;cap rollback&#8221; from the command window.  Refresh your browser.  You should see the original page we saw after doing the first deploy.  Nifty, huh?  Now we can just do a &#8220;cap deploy&#8221; to see our updated page.&lt;/p&gt;


	&lt;p&gt;That&#8217;s deploying and rollback changes to a rails app in a nutshell.  There&#8217;s about a bajillion more things you can do with Capistrano like deploying apps to multiple servers, etc.  There&#8217;s tons of info you can find out in GoogleLand.  Hopefully this tutorial has helped you get your first pretty trivial rails app deployed out to Dreamhost.  The principles should remain the same for more and more complicated websites.  So, get to capping and have fun!&lt;/p&gt;


	&lt;p&gt;Please take a look at the wiki article mentioned at the top of this tutorial for more information and some helpful hints.  It&#8217;s also very worthwhile to take a look at the &lt;a href=&quot;http://manuals.rubyonrails.com/read/book/17&quot;&gt;Capistrano book&lt;/a&gt; up at RubyOnRails.org.&lt;/p&gt;


	&lt;p&gt;As usual, I&#8217;m a noob, so please feel free to correct me whereever I&#8217;ve screwed up, enlighten me on things I don&#8217;t know, or belittle me just for the hell of it.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>TDonaghe</name>
    </author>
    <id>tag:www.rubynoob.com,2006-08-21:45</id>
    <published>2006-08-21T10:23:00Z</published>
    <updated>2007-07-11T19:25:31Z</updated>
    <category term="HowTo"/>
    <category term="Just Ruby"/>
    <category term="download"/>
    <category term="file"/>
    <category term="howto"/>
    <category term="picture"/>
    <category term="ruby"/>
    <link href="http://www.rubynoob.com/articles/2006/8/21/how-to-download-files-with-a-ruby-script" rel="alternate" type="text/html"/>
    <title>How to download files with a Ruby script</title>
<content type="html">
            For a project that I'm working on, I want to download a set of pictures from &lt;a href=&quot;http://www.flickr.com&quot;&gt;flickr&lt;/a&gt; once a day.  In this way, my Rails app won't need to access the &lt;a href=&quot;http://www.flickr.com/services/api/&quot;&gt;flickr api&lt;/a&gt; - it can just grab the pics out of an images directory.&lt;br /&gt;
&lt;br /&gt;
I figured that it would be an awfully easy task to download pictures from the internet using Ruby, and it is, but it was very difficult to find good examples.  I googled for an hour or so, and kept coming up empty-handed.  Finally, I checked in gmail where I keep mail from the &lt;a href=&quot;http://www.ruby-lang.org/en/20020104.html&quot;&gt;Ruby Language mailing list&lt;/a&gt;.  I found a relatively straightfoward way to do this.&lt;br /&gt;
&lt;br /&gt;
Let's say that you want to download a picture from flickr, and you know its URL.  Here's the ruby script to download the file:&lt;br /&gt;
&lt;br /&gt;
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;5&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;require &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;net/http&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class=&quot;co&quot;&gt;Net&lt;/span&gt;::&lt;span class=&quot;co&quot;&gt;HTTP&lt;/span&gt;.start(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;static.flickr.com&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) { |http|&lt;tt&gt;
&lt;/tt&gt;  resp = http.get(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;/92/218926700_ecedc5fef7_o.jpg&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;  open(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;fun.jpg&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;wb&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) { |file|&lt;tt&gt;
&lt;/tt&gt;    file.write(resp.body)&lt;tt&gt;
&lt;/tt&gt;   }&lt;tt&gt;
&lt;/tt&gt;}&lt;tt&gt;
&lt;/tt&gt;puts &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Yay!!&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

&lt;br /&gt;
The Net::HTTP class contains the magic needed to handle this operation.  I don't think this will work at all if you need to pull down a file from an FTP server.  For now, we're dealing with http urls.  So, just strip off the &quot;http://&quot; portion of the url and everything after that up to the first / goes into the start method.&lt;br /&gt;
&lt;br /&gt;
Now, we get the file.  The rest of your image url after what you put in the start method goes into the get method.  This grabs the file from flickr.&lt;br /&gt;
&lt;br /&gt;
Now we're going to copy the file down to where the script is running.  First, let's create the file we're going to copy the picture into.  Using the open method, the first parameter is the name of the file that you're going to plop the picture into.  We could have used &quot;218926700_ecedc5fef7_o.jpg&quot; or anything else here.  The second parameter of the open method, &quot;wb&quot; indicates that we're opening the file for (w)riting and we're going to be writing (b)inary information.  The &quot;b&quot; may not be necessary on non-Windows platforms.&lt;br /&gt;
&lt;br /&gt;
Finally, we're going to write into the new file, the contents or &quot;body&quot; of what we grabbed from flickr.  So, this writes in the binary bits of the picture into fun.jpg.  Remember that with the way that we created fun.jpg it'll be in the same directory with our ruby script.&lt;br /&gt;
&lt;br /&gt;
This same method will copy down .html files, .css files, .pdf's and just about any other kind of file.  In my next RubyNoob entry, I'll write about how to combine this method with a flickr api call to grab an arbitrary number of recent photos from flickr.  As usual, I'm still a noob, and there's probably much better ways to do this.  If you know a better way, please share in the comment section below.
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>TDonaghe</name>
    </author>
    <id>tag:www.rubynoob.com,2006-07-22:44</id>
    <published>2006-07-22T17:25:00Z</published>
    <updated>2007-06-11T02:49:27Z</updated>
    <link href="http://www.rubynoob.com/articles/2006/7/22/how-to-create-and-use-subversion-repositories-with-windows-and-dreamhost" rel="alternate" type="text/html"/>
    <title>How to create and use subversion repositories with Windows and Dreamhost</title>
<summary type="html">&lt;p&gt;I currently do my development work on a WindowsXP PC running Subversion through Tortoise and I&#8217;m currently hosting sites with Dreamhost, a popular site for Ruby on Rails and &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; hosting.  This is going to be a tutorial on how to get your rails apps up in a repository on Dreamhost, but you&#8217;ll be able to use to coordinate any sort of subversion repository on dreamhost.&lt;br /&gt;
&lt;br /&gt;&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;I currently do my development work on a WindowsXP PC running Subversion through Tortoise and I&#8217;m currently hosting sites with Dreamhost, a popular site for Ruby on Rails and &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; hosting.  This is going to be a tutorial on how to get your rails apps up in a repository on Dreamhost, but you&#8217;ll be able to use to coordinate any sort of subversion repository on dreamhost.&lt;br /&gt;
&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;First, let&#8217;s use the nifty tool that Dreamhost has provided for creating Subversion repositories.  Go into your ControlPanel.  Drill down into the Goodies menu and choose Subversion.  You&#8217;ll see a dialog that looks like this:&lt;br /&gt;
&lt;br /&gt;
Use whatever name you&#8217;d like and make sure to give it a useful Username and Password.  Then you press the create button.  On success you&#8217;ll see something like this:&lt;br /&gt;
&lt;br /&gt;
In a few minutes you&#8217;ll receive an email from Dreamhost declaring that your new repository is now working.  So, now let&#8217;s fill it with some stuff.&lt;br /&gt;
&lt;br /&gt;
The easiest way to interact with Subversion under WindowsXP is to install the super excellent Tortoise software.  This extends your Windows Explorer shell with the full functionality of Tortoise.  We&#8217;ll look at this as we go through the tutorial.  If you haven&#8217;t yet, please install Tortoise.&lt;br /&gt;
&lt;br /&gt;
Now we need something to stick into our new Subversion project.  Let&#8217;s create a new rails application.  That&#8217;ll create all sorts of stuff.  Go into the directory where you have your Rails apps and type something like:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;
rails SubSample
&lt;/code&gt;&lt;/pre&gt;
After that&#8217;s done, let&#8217;s load up our new repository.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>TDonaghe</name>
    </author>
    <id>tag:www.rubynoob.com,2006-07-13:43</id>
    <published>2006-07-13T12:23:24Z</published>
    <updated>2007-06-11T02:21:03Z</updated>
    <category term="Ruby on Rails"/>
    <category term="ruby"/>
    <category term="rubyonrails"/>
    <link href="http://www.rubynoob.com/articles/2006/7/13/the-20-coolest-ruby-apps-you-apos-ve-never-heard-of" rel="alternate" type="text/html"/>
    <title>The 20 Coolest Ruby Apps You&amp;apos;ve Never Heard Of</title>
<content type="html">
            &lt;a href=&quot;http://www.redferret.net/?p=7211&quot;&gt;The 20 Coolest Ruby Apps youâ€™ve never heard ofâ€¦&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Actually, I have heard of a few of these.  BillMonk is a pretty darned cool idea for the younger, poor college aged crowd.  CommunityWalk is another of my favorites, but I didn't realize it was written in Rails.&lt;br /&gt;
&lt;br /&gt;
&lt;p /&gt;&lt;p&gt;Blogged with &lt;a href=&quot;http://www.flock.com&quot; title=&quot;Flock&quot;&gt;Flock&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>TDonaghe</name>
    </author>
    <id>tag:www.rubynoob.com,2006-07-09:42</id>
    <published>2006-07-09T09:55:00Z</published>
    <updated>2007-07-17T22:50:32Z</updated>
    <category term="Ruby on Rails"/>
    <category term="rails"/>
    <category term="resources"/>
    <category term="ruby"/>
    <category term="rubyinside"/>
    <category term="rubyonrails"/>
    <link href="http://www.rubynoob.com/articles/2006/7/9/more-fantastic-resources" rel="alternate" type="text/html"/>
    <title>More fantastic resources</title>
<content type="html">
            &lt;a href=&quot;http://www.rubyinside.com/19-rails-tricks-most-rails-coders-dont-know-131.html&quot;&gt;19 Rails Tricks Most Rails Coders Don't Know&quot;&lt;/a&gt;

RubyInside.com does it again!  This is a great list of Rails shortcuts that us mere mortals will probably come to rely on.  Thanks guys!
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>TDonaghe</name>
    </author>
    <id>tag:www.rubynoob.com,2006-07-05:40</id>
    <published>2006-07-05T16:12:40Z</published>
    <updated>2007-06-11T02:21:03Z</updated>
    <category term="Ruby on Rails"/>
    <link href="http://www.rubynoob.com/articles/2006/7/5/excellent-rjs-reference-list" rel="alternate" type="text/html"/>
    <title>Excellent RJS Reference List</title>
<content type="html">
            &lt;a href=&quot;http://www.rubyinside.com/16-rjs-resources-and-tutorials-for-rails-programmers-5.html&quot;&gt;16 RJS Resources and Tutorials for Rails Programmers&lt;/a&gt;

This is a great list of resources for RJS stuff, not the least of which because it has a link here!  And yes, I'm back (again)!
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>TDonaghe</name>
    </author>
    <id>tag:www.rubynoob.com,2006-06-01:39</id>
    <published>2006-06-01T23:16:22Z</published>
    <updated>2007-06-11T02:21:03Z</updated>
    <category term="RubyNoob"/>
    <category term="lightbox"/>
    <category term="v2"/>
    <link href="http://www.rubynoob.com/articles/2006/6/1/lightbox-version-2" rel="alternate" type="text/html"/>
    <title>Lightbox Version 2</title>
<content type="html">
            I realize this is probably really old news, but I'm really excited now to see the second version of lightbox!  Check &lt;a href=&quot;http://www.huddletogether.com/projects/lightbox2/&quot;&gt;this link&lt;/a&gt;.  I'm going to delay showing off my little flickr app until I can integrate this new stuff.  I've been off procrastinating for a while, but now I'm motivated again.
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>TDonaghe</name>
    </author>
    <id>tag:www.rubynoob.com,2006-05-30:38</id>
    <published>2006-05-30T16:57:16Z</published>
    <updated>2007-06-11T02:21:03Z</updated>
    <category term="RubyNoob"/>
    <link href="http://www.rubynoob.com/articles/2006/5/30/still-here" rel="alternate" type="text/html"/>
    <title>Still here!</title>
<content type="html">
            Hi everyone.  Just posting because I haven't posted in a while and I don't want people to think I've abandoned RubyNoob!  I'm hoping to have an extended version of the famous Flickr example available for download soon!
          </content>  </entry>
  <entry xml:base="http://www.rubynoob.com/">
    <author>
      <name>TDonaghe</name>
    </author>
    <id>tag:www.rubynoob.com,2006-05-19:37</id>
    <published>2006-05-19T14:34:21Z</published>
    <updated>2007-06-11T02:21:03Z</updated>
    <category term="HowTo"/>
    <category term="Ruby on Rails"/>
    <category term="files"/>
    <category term="howto"/>
    <category term="rails"/>
    <category term="rubynoob"/>
    <category term="rubyonrails"/>
    <link href="http://www.rubynoob.com/articles/2006/5/19/how-to-send-files-in-rails" rel="alternate" type="text/html"/>
    <title>How to Send Files in Rails</title>
<content type="html">
            Setting up a link in your Rails app to allow your users to download any file is incredibly easy.  Not just 

incredibly easy - OMGWTHBBQ easy!  Stuff like this makes Rails so cool!&lt;br /&gt;
&lt;br /&gt;
First, put the file out on your server.  I put my &quot;README.txt&quot; file in a &quot;files&quot; folder like this: &quot;rails/

appname/files/README.txt.&quot;&lt;br /&gt;
&lt;br /&gt;
Next, set up a link in one of your pages:
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;&amp;lt;%= link_to &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Get Readme&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:action&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;get_readme&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;


Finally, add the &quot;get_readme&quot; action method to your controller:
&lt;table class=&quot;CodeRay&quot;&gt;&lt;tr&gt;
  &lt;td title=&quot;click to toggle&quot; class=&quot;line_numbers&quot;&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;get_readme&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;    send_file(&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;files/README.txt&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:filename&lt;/span&gt; =&amp;gt; &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;yo_readme.txt&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;/span&gt;)&lt;tt&gt;
&lt;/tt&gt;  &lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;

That's it!  Now, whenever a user clicks the &quot;Get Readme&quot; link on your page, the file will be sent to the 

client.  The :filename option simply allows you to suggest a name for the file to your users.  I threw it in 

just to see how it works.  I couldn't believe it was this easy, but sure enough, it is.  Very cool.&lt;br /&gt;
&lt;br /&gt;
There are other options like the :filename option which allow you to tell the browser what type of file to expect, how to display the file, and whether or not to stream the download.  Streaming is turned on by default and allows downloading of very large files.  All of these options go into the same line of code.  Take a look at the article at this &lt;a href=&quot;http://api.rubyonrails.org/classes/ActionController/Streaming.html#M000072&quot;&gt;link&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
As usual, expect a quick video demonstration of this posted later tonight.
          </content>  </entry>
</feed>
