{"id":37,"date":"2011-04-28T02:40:18","date_gmt":"2011-04-28T07:40:18","guid":{"rendered":"http:\/\/trillworks.com\/nick\/?p=37"},"modified":"2012-04-10T23:47:39","modified_gmt":"2012-04-11T04:47:39","slug":"ruby-on-rails-a-first-look","status":"publish","type":"post","link":"https:\/\/trillworks.com\/nick\/2011\/04\/28\/ruby-on-rails-a-first-look\/","title":{"rendered":"Ruby on Rails: A first look"},"content":{"rendered":"<p>I&#8217;ve been writing PHP apps for about 5 years, but it&#8217;s time to learn Ruby and its popular framework, Rails. Since there is already great documentation available, I&#8217;ll only cover the trouble spots that I&#8217;ve encountered.<\/p>\n<p>I began with Ruby itself and followed this <a href=\"http:\/\/www.ruby-lang.org\/en\/documentation\/quickstart\/\">quick introduction<\/a> to Ruby&#8217;s data types, object orientation,\u00a0and iteration methods. It&#8217;s a lot to swallow if you&#8217;ve spent most of your time writing in C-style languages, but I can understand the appeal of the syntax. If you&#8217;re just starting out it&#8217;s probably a good idea to spend more time with Ruby proper. Later it can be easy to conflate Ruby with Rails if both are foreign.<\/p>\n<p>To get up and running with Rails on Arch Linux I followed <a href=\"https:\/\/wiki.archlinux.org\/index.php\/RubyOnRails\">the guide<\/a> on the official Arch wiki. I ran into a little trouble at the database section. The sqlite package is called sqlite3-ruby package has been renamed to sqlite-3. A proper install requires a<br \/>\n<code># pacman -S sqlite3 <\/code><br \/>\nand then a<br \/>\n<code># \u00a0gem install sqlite3 <\/code><\/p>\n<p>I opted to use the Passenger Apache module rather than WEBrick because I plan to host production applications on this server eventually and it makes sense for Apache to serve everything. If you just want to play around with Rails, it&#8217;s probably a better idea to go ahead with WEBrick because Apache requires a little configuration.<\/p>\n<p>Pacman will spit out some configuration information for Passenger and it&#8217;s important to get it right. Rails&#8217; official <a href=\"http:\/\/guides.rubyonrails.org\/getting_started.html\">Getting Started<\/a> guide is specific to WEBrick so it doesn&#8217;t tell you that the Document Root line in your httpd.conf should point to the public folder of your rails application. I wasted some time staring at an Apache index trying to figure out why the app wouldn&#8217;t execute. Just do something like this:<\/p>\n<pre class=\"brush:applescript\">&lt;VirtualHost *:80&gt;\r\nServerName rails.trillworks.com\r\nDocumentRoot \/path\/rails\/application\/public\r\nRailsBaseURI \/path\/rails\r\n&lt;Directory \/path\/rails\/application\/public&gt;\r\nAllowOverride all\r\nOptions -MultiViews\r\n&lt;\/Directory&gt;\r\n&lt;\/VirtualHost&gt;<\/pre>\n<p>Don&#8217;t forget these lines either:<\/p>\n<pre class=\"brush:plain\">LoadModule passenger_module \/usr\/lib\/ruby\/gems\/1.9.1\/gems\/passenger-3.0.7\/ext\/apache2\/mod_passenger.soPassengerRoot \/usr\/lib\/ruby\/gems\/1.9.1\/gems\/passenger-3.0.7PassengerRuby \/usr\/bin\/ruby\r\nRailsEnv development<\/pre>\n<p>That last line is vital to get the blog example from the Getting Started guide working smoothly. Passenger runs your app in production mode by default, but that won&#8217;t work because the migrate command in the guide creates tables in the development table.<\/p>\n<p>The blog app in the guide has a decent introduction to Ruby&#8217;s take on MVC and how to wire up the various components. Stay tuned for some real apps.<\/p>\n<p>References<br \/>\n<a href=\"http:\/\/www.fngtps.com\/2008\/04\/using-passenger-on-osx-for-rails-development\">http:\/\/www.fngtps.com\/2008\/04\/using-passenger-on-osx-for-rails-development<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been writing PHP apps for about 5 years, but it&#8217;s time to learn Ruby and its popular framework, Rails. Since there is already great documentation available, I&#8217;ll only cover the trouble spots that I&#8217;ve encountered. I began with Ruby itself and followed this quick introduction to Ruby&#8217;s data types, object orientation,\u00a0and iteration methods. It&#8217;s &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/trillworks.com\/nick\/2011\/04\/28\/ruby-on-rails-a-first-look\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Ruby on Rails: A first look&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77],"tags":[],"class_list":["post-37","post","type-post","status-publish","format-standard","hentry","category-technical"],"_links":{"self":[{"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/posts\/37","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/comments?post=37"}],"version-history":[{"count":22,"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/posts\/37\/revisions"}],"predecessor-version":[{"id":63,"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/posts\/37\/revisions\/63"}],"wp:attachment":[{"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/media?parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/categories?post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trillworks.com\/nick\/wp-json\/wp\/v2\/tags?post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}