<?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>occasionally useful &#187; webapp</title>
	<atom:link href="http://blog.maxaller.name/category/ruby/webapp/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.maxaller.name</link>
	<description>ruby, ubuntu, etc</description>
	<lastBuildDate>Sun, 11 Jul 2010 07:01:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A brief introduction to Ruby, Sinatra, and Haml</title>
		<link>http://blog.maxaller.name/2010/01/a-brief-introduction-to-ruby-sinatra-and-haml/</link>
		<comments>http://blog.maxaller.name/2010/01/a-brief-introduction-to-ruby-sinatra-and-haml/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 20:01:05 +0000</pubDate>
		<dc:creator>Max</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://blog.maxaller.name/?p=251</guid>
		<description><![CDATA[Ruby and Sinatra make it ludicrously easy to make a webapp, but getting started, as with any new language or framework, can be daunting.  By the end of this part, you'll have a simple template that talks back to you!

I'm not going to go over how to install Ruby here (it's probably been done [...]]]></description>
			<content:encoded><![CDATA[<p>Ruby and Sinatra make it ludicrously easy to make a webapp, but getting started, as with any new language or framework, can be daunting.  By the end of this part, you'll have a simple template that talks back to you!<br />
<span id="more-251"></span><br />
I'm not going to go over how to install Ruby here (it's probably been done numerous times around the web), but here's a quick checklist:<br />
1) Install Ruby (http://www.ruby-lang.org/en/downloads/)<br />
2) If running Ruby 1.8.6 or 1.8.7 (check with ruby -v), install Rubygems.  For more info on Rubygems, check out http://docs.rubygems.org/read/book/1 .  Ruby 1.9 and above come with Rubygems built in.<br />
3) Install the Sinatra and Haml rubygems (see http://docs.rubygems.org/read/chapter/2#page5, but the command on Linux is sudo gem install sinatra haml to install both at the same time)</p>
<p>As a sanity check when you're done, run "irb" (interactive Ruby), and type each of the following commands (in order).  None of them should return errors.</p>
<ol>
<li>require 'rubygems'</li>
<li>require 'sinatra'</li>
<li>require 'haml'</li>
</ol>
<p>Okay, now on with the good stuff.</p>
<h2>First Steps</h2>
<p>Create a project directory, like first_app or something.  Create a file with the .rb extension, like hello.rb.  Open it up in your favorite (simple?) text editor (notepad++, gedit, TextMate).</p>
<p>Write the following:<br />
<script src="http://gist.github.com/284715.js?file=learning_ruby1.rb"></script></p>
<p>Let's take a step by step to figure out exactly what's going on in this file.  (list numbers correspond to line numbers)</p>
<ol>
<li>"require" simply loads up a library.  If it's already been loaded once, "require" will check to make sure it already loaded it and then do nothing.  "require"ing rubygems loads up that library into memory so we can load other gems, like...sinatra.  (Like Perl, Ruby has a number of "magic globals".  The load path, where require looks, is an array in $:).  Also, notice single-line comments are denoted by #.  Ruby doesn't really have multiline comments amazingly, but there is a hacky substitute...</li>
<li>Now that we have rubygems loaded, we can load sinatra!  Rubygems works by modifying that $: variable I mentioned above.  By loading the sinatra gem, the libraries full capabilities are now ready -- and most importantly, new methods are available in the main scope.</li>
<li></li>
<li>Ah, 'get' is our first method call, which we get after loading sinatra.  We're passing in one argument to it, "/hello", as well as a block.  Blocks have some tricky aspects to them, but think of them as simply a way of passing a chunk of code around (see <a href="http://en.wikipedia.org/wiki/Closure_%28computer_science%29">closure</a> and <a href="http://ruby-doc.org/docs/ProgrammingRuby/html/tut_containers.html">Pragmatic Programmers</a> for more info).  Note that calling methods without the (optional) parentheses is generally considered against best practice, except in very simple cases, like this one.</li>
<li>As you may have guessed, this is a string.  But what is it doing?  The last line of any block or method is implicitly the return value.  When sinatra asks this block "what's your value", the block will hand up whatever's on the last line.  Of course, you can (and sometimes have to) be more explicit by prefixing your return value with the <strong>return</strong> keyword, like Java.</li>
</ol>
<p>If you're confused about what method calls generally look like, here's a little <a href="http://gist.github.com/284715#file_method_call_examples.rb">snippet</a> I prepared.</p>
<p>Okay, let's run this thing.  In your terminal, run `ruby hello.rb`.  The terminal will tell you where to point your browser: http://localhost:4567/.  Go there -- you should see "Hello, world!"</p>
<p>Okay, the basics are out of the way.  Let's get to the cookbook-style programs.  (be sure to note the filename, in the corner of the gist)</p>
<h2>Render a haml template and pass data to it</h2>
<p><script src="http://gist.github.com/284756.js"></script></p>
<h2>Render a layout</h2>
<p>Layouts minimize redundant code across multiple views.<br />
<script src="http://gist.github.com/284757.js"></script></p>
<h2>Adding javascript, css, images</h2>
<p>Plop those files into a /public subdirectory and you should be able to reference them like /my_css.css in your views.  See here: <a href="http://www.sinatrarb.com/intro.html">Sinatra Intro</a>.</p>
<h2>Posting a form and using that data</h2>
<p><script src="http://gist.github.com/284762.js"></script></p>
<h2>Preserving session information, like logins</h2>
<p>The Sinatra FAQ is pretty good about this one: <a href="http://www.sinatrarb.com/faq.html#sessions">http://www.sinatrarb.com/faq.html#sessions</a></p>
<p>I'm cutting this off a bit short, but hopefully this is enough to get you started.</p>
<p>EDIT: cont'd.</p>
<h2>Basic HTML/HAML stuff</h2>
<p><script src="http://gist.github.com/284781.js"></script></p>
<h2>A basic "sign in" application with link bar</h2>
<p>See this little app I made at <a href="http://github.com/nanodeath/SinatraHamlSignin">github</a>.  Click the Download Source button on that page, and/or browse around online.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxaller.name/2010/01/a-brief-introduction-to-ruby-sinatra-and-haml/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Cool free hosted tools for your Ruby webapp</title>
		<link>http://blog.maxaller.name/2009/11/cool-free-hosted-tools-for-your-ruby-webapp/</link>
		<comments>http://blog.maxaller.name/2009/11/cool-free-hosted-tools-for-your-ruby-webapp/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 02:15:51 +0000</pubDate>
		<dc:creator>Max</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://blog.maxaller.name/?p=211</guid>
		<description><![CDATA[Some of these are obvious (i.e. get exceptional, hoptoad), many of these aren't Ruby-specific, but I thought it might be nice to put all these in one place, at least for my sake.
Exception tracking
Get Exceptional limit: 1 app
Hoptoad limit: 1 project, 2 users
Bug tracking:
there's github, of course, if you're already using that...
16bugs limit: 1 project
I'm [...]]]></description>
			<content:encoded><![CDATA[<p>Some of these are obvious (i.e. get exceptional, hoptoad), many of these aren't Ruby-specific, but I thought it might be nice to put all these in one place, at least for my sake.</p>
<h2>Exception tracking</h2>
<p><a href="http://getexceptional.com/" target="_blank">Get Exceptional</a> limit: 1 app<br />
<a href="https://hoptoadapp.com/account/new" target="_blank">Hoptoad</a> limit: 1 project, 2 users</p>
<h2>Bug tracking:</h2>
<p>there's github, of course, if you're already using that...<br />
<a href="http://16bugs.com/pricing" target="_blank">16bugs</a> limit: 1 project<br />
I'm not including full hosting platforms, like Google Code here, but you could use those, too</p>
<h2>Email</h2>
<h3>One-off emails (i.e. signup)</h3>
<p><a href="http://sendgrid.com/pricing.html" target="_blank">Sendgrid</a> limit: 200 emails/day<br />
GMail allows 500 emails/day, but doesn't offer all the doodads that Sendgrid does</p>
<h3>Mailing list (i.e. newsletter)</h3>
<p><a href="http://www.mailchimp.com/pricing/" target="_blank">Mailchimp</a> limit: 500 subscribers, 3000 emails total a month</p>
<h2>Customer Support</h2>
<p><a href="http://www.snapabug.com/plans.jsp" target="_blank">SnapABug</a> limit: 10 reports/day<br />
<a href="https://uservoice.com/signup" target="_blank">uservoice</a> limit: 100 unique users/month<br />
<a href="http://getsatisfaction.com/features" target="_blank">GetSatisfaction</a> limit: 0 official reps, not hosted on your url</p>
<h2>Analytics</h2>
<p>There's a ton of options in this space, but I use:<br />
<a href="http://www.google.com/analytics/" target="_blank">Google Analytics</a> limit: no limits, because it's The Goog<br />
<a href="http://getclicky.com/" target="_blank">Clicky</a> limit: 1 website, 3000 hits/day</p>
<h2>Metrics, Monitoring</h2>
<p><a href="http://www.newrelic.com/get-RPM.html" target="_blank">New Relic</a> limit: no troubleshooting, optimization, etc</p>
<h2>User Avatar Hosting</h2>
<p><a href="http://www.gravatar.com/" target="_blank">Gravatar</a> limit: none</p>
<h2>Authentication</h2>
<h3>OpenID</h3>
<p><a href="https://rpxnow.com/get" target="_blank">RPX</a> limit: up to 6 providers, instead of 12</p>
<h2>Time tracking/invoicing</h2>
<p><a href="http://www.getharvest.com/pricing" target="_blank">Harvest</a> limit: 2 projects, 4 clients, 1 user</p>
<h2>Help desk thing</h2>
<p>Just kidding, couldn't find any free hosted help desk apps</p>
<p>Anything else I'm missing that every webapp needs?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxaller.name/2009/11/cool-free-hosted-tools-for-your-ruby-webapp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
