<?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>Icebergist &#187; Ruby and Rails</title>
	<atom:link href="http://icebergist.com/category/ruby-and-rails/feed" rel="self" type="application/rss+xml" />
	<link>http://icebergist.com</link>
	<description>Exploring hidden depths of web apps business</description>
	<lastBuildDate>Mon, 24 Jan 2011 17:24:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.2</generator>
		<item>
		<title>Paperclip, Heroku and Amazon S3 credentials</title>
		<link>http://icebergist.com/posts/paperclip-heroku-and-amazon-s3-credentials</link>
		<comments>http://icebergist.com/posts/paperclip-heroku-and-amazon-s3-credentials#comments</comments>
		<pubDate>Mon, 24 Jan 2011 17:19:33 +0000</pubDate>
		<dc:creator>Slobodan Kovačević</dc:creator>
				<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[amazon s3]]></category>
		<category><![CDATA[heroku]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://icebergist.com/?p=45</guid>
		<description><![CDATA[Setting up Paperclip to use Amazon&#8217;s S3 is as simple as setting :storage =&#62; :s3 and providing right credentials to Paperclip by setting :s3_credentials option. Best way to provide S3 credentials is to use an YML file (usually config/s3.yml) which allows you to set different credentials for each environment. For example: # config/s3.yml development: access_key_id: [...]]]></description>
			<content:encoded><![CDATA[<p>Setting up Paperclip to use Amazon&#8217;s S3 is as simple as setting :storage =&gt; :s3 and providing right credentials to Paperclip by setting :s3_credentials option. Best way to provide S3 credentials is to use an YML file (usually config/s3.yml) which allows you to set different credentials for each environment. For example:</p>
<pre>
# config/s3.yml
development:
  access_key_id: XYZXYZXYZ
  secret_access_key: XYZXYZXYZ
  bucket: mygreatapp-development
production:
  access_key_id: XYZXYZXYZ
  secret_access_key: XYZXYZXYZ
  bucket: mygreatapp-production
</pre>
<p>Of course you want to treat s3.yml same as database.yml &#8211; i.e. you don&#8217;t want to track it with git and you want for each person/server to have it&#8217;s own.</p>
<p>However, consider this: you are working on Open Source app in a public git repository and you are deploying it on Heroku. Heroku doesn&#8217;t allow you to create files (unless they are in git repository) and you can&#8217;t commit s3.yml with your credentials to public repository.</p>
<p>One solution is to define different :s3_credentials hash in one of the environment files or to load different YML file for each environment and generate hash from it. Downside is that you need to have a separate YML file for each environment and/or you need to convert YML to hash. Other solution could be to have separate local branch from which you will push to Heroku. Problem with this is that you have to have a local branch for deploying. This means if there are multiple developers who deploy to production each should have separate local branch.</p>
<p>Much simpler way to deploy Paperclip with different S3 credentials for each environment (with one of the environment being deployed on Heroku; and repository being public) is to create s3.yml file as usual (and don&#8217;t commit it to git), but define values only for local environment.</p>
<p>For production deployment on Heroku you can write initializer which will set :s3_credentials from ENV variables.</p>
<pre>
# initializers/s3.rb
if Rails.env == "production"
  # set credentials from ENV hash
  S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET'], :bucket => "sharedearth-production"}
else
  # get credentials from YML file
  S3_CREDENTIALS = Rails.root.join("config/s3.yml")
end

# in your model
has_attached_file :photo, :storage => :s3, :s3_credentials => S3_CREDENTIALS
</pre>
<p>and you can easily set persistant ENV vars on Heroku with:</p>
<pre>
$ heroku config:add S3_KEY=XYZXYZ S3_SECRET=XYZXYZ
</pre>
<p>(<a href="http://docs.heroku.com/config-vars#quick-example">according to Heroku docs</a>)</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://icebergist.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://icebergist.com/posts/paperclip-heroku-and-amazon-s3-credentials/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rails 3 reading list</title>
		<link>http://icebergist.com/posts/rails-3-reading-list</link>
		<comments>http://icebergist.com/posts/rails-3-reading-list#comments</comments>
		<pubDate>Mon, 29 Mar 2010 13:14:23 +0000</pubDate>
		<dc:creator>Slobodan Kovačević</dc:creator>
				<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rails3]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://icebergist.com/?p=38</guid>
		<description><![CDATA[I&#8217;ve been planning to catchup with all the new Rails 3 stuff. To get me started I&#8217;ve compiled a small Rails 3 related reading list. Ruby on Rails 3.0 Release Notes Active Record Query Interface 3.0 The Skinny on Scopes (Formerly named_scope) Rails 3 Beautiful Code Railscasts &#8211; rails-3.0 episodes jQuery with Rails 3 The [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been planning to catchup with all the new Rails 3 stuff. To get me started I&#8217;ve compiled a small Rails 3 related reading list.</p>
<ol>
<li><a href="http://guides.rails.info/3_0_release_notes.html">Ruby on Rails 3.0 Release Notes</a></li>
<li><a href="http://m.onkey.org/2010/1/22/active-record-query-interface">Active Record Query Interface 3.0</a></li>
<li><a href="http://edgerails.info/articles/what-s-new-in-edge-rails/2010/02/23/the-skinny-on-scopes-formerly-named-scope/">The Skinny on Scopes (Formerly named_scope)</a></li>
<li><a href="http://blog.envylabs.com/2010/02/rails-3-beautiful-code/">Rails 3 Beautiful Code</a></li>
<li><a href="http://railscasts.com/tags/27">Railscasts &#8211; rails-3.0 episodes</a></li>
<li><a href="http://joshhuckabee.com/jquery-rails-3">jQuery with Rails 3</a></li>
<li><a href="http://litanyagainstfear.com/blog/2010/02/03/the-rails-module/">The Rails Module (in Rails 3)</a></li>
</ol>
<p>Once I&#8217;m done with it I plan to get even more from:</p>
<ul>
<li><a href="http://edgerails.info/articles/what-s-new-in-edge-rails/2010/02/10/rails-3-resources/">Rails 3 Resources</a></li>
<li><a href="http://www.rubyinside.com/rails-3-0-beta-links-2966.html">Rails 3.0 Beta: 36 Links and Resources To Get You Going</a></li>
</ul>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://icebergist.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://icebergist.com/posts/rails-3-reading-list/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expected x.rb to define X (LoadError)</title>
		<link>http://icebergist.com/posts/expected-xrb-to-define-x-loaderror</link>
		<comments>http://icebergist.com/posts/expected-xrb-to-define-x-loaderror#comments</comments>
		<pubDate>Wed, 15 Apr 2009 16:00:56 +0000</pubDate>
		<dc:creator>Slobodan Kovačević</dc:creator>
				<category><![CDATA[Ruby and Rails]]></category>

		<guid isPermaLink="false">http://icebergist.com/?p=33</guid>
		<description><![CDATA[I have been working on extending Rails&#8217; I18n Simple backend to make it work with Serbian grammar (post on that will follow soon), but I kept getting an error: Expected ./lib/serbian_simple.rb to define SerbianSimple (LoadError) I&#8217;ve just spent an hour trying to figure out why this keeps happening and I found that there&#8217;s a lot [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on extending Rails&#8217; I18n Simple backend to make it work with Serbian grammar (post on that will follow soon), but I kept getting an error:</p>
<p><code>Expected ./lib/serbian_simple.rb to define SerbianSimple (LoadError)</code></p>
<p>I&#8217;ve just spent an hour trying to figure out why this keeps happening and I found that there&#8217;s a lot of people with similar problem.</p>
<p>It seems that the problem appears when Rails tries to autoload files. In my case there was a simple solution &#8211; I just added require &#8216;serbian_simple.rb&#8217; in environment.rb to manually load the file.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://icebergist.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://icebergist.com/posts/expected-xrb-to-define-x-loaderror/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RESTful admin namespaced controller using scaffolding</title>
		<link>http://icebergist.com/posts/restful-admin-namespaced-controller-using-scaffolding</link>
		<comments>http://icebergist.com/posts/restful-admin-namespaced-controller-using-scaffolding#comments</comments>
		<pubDate>Wed, 17 Sep 2008 20:58:56 +0000</pubDate>
		<dc:creator>Slobodan Kovačević</dc:creator>
				<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[restful]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scaffold]]></category>

		<guid isPermaLink="false">http://icebergist.com/?p=14</guid>
		<description><![CDATA[Most of my clients prefer to have a separate admin section. In turn, I like to have separate controllers for admin section and front-end in my Rails app. This is not as straightforward as it might seem, especially if you like to use scaffolding for admin controller. The goal is to get 2 separate RESTful [...]]]></description>
			<content:encoded><![CDATA[<p>Most of my clients prefer to have a separate admin section. In turn, I like to have separate controllers for admin section and front-end in my Rails app. This is not as straightforward as it might seem, especially if you like to use scaffolding for admin controller.</p>
<p>The goal is to get 2 separate RESTful controllers, admin &amp; front-end controller, one model and for admin pages to have scaffolding.</p>
<p>Here is the easiest way I found so far to accomplish this. This example generates categories model and controllers for it.</p>
<p><code>./script/generate controller admin/categories<br />
./script/generate scaffold category name:string</code></p>
<p>This will generate an empty controller in admin namespace and a scaffolded resource for front-end controller.</p>
<p>Now we have everything generated we just need to make it work with admin controller and not with front-end.</p>
<ul>
<li>move all templates from app/views/categories to app/views/<strong>admin</strong>/categories</li>
<li>copy all functions from categories_controller.rb to admin/categories_controller.rb</li>
<li>add namespace for admin controller in routes.rb:<code>map.namespace :admin do |admin|<br />
admin.resources :categories<br />
end</code></li>
<li>in admin/categories_controller.rb replace in 3 places redirect_to calls to work with admin namespace. It will have something like redirect_to(@category), but to work with namespace it needs to have redirect_to([:admin, @category])</li>
<li>make similar changes in all templates, i.e. make it work within an admin namespace. You need to make following changes:
<ul>
<li>form_for(@category) =&gt; <strong>form_for([:admin, @category])</strong></li>
<li>&lt;%= link_to &#8216;Show&#8217;, @category %&gt; =&gt; <strong>&lt;%= link_to &#8216;Show&#8217;, [:admin, @category] %&gt;</strong></li>
<li>categories_path =&gt; <strong>admin_categories_path</strong></li>
<li>edit_category_path(@category) =&gt; <strong>edit_admin_category_path(@category)</strong></li>
<li>new_category_path =&gt; <strong>new_admin_category_path</strong></li>
</ul>
</li>
</ul>
<p>That&#8217;s it. Now you&#8217;ll have /admin/categories for all administrative tasks and you have a free controller for front-end actions.</p>
<p>You might wonder why not just generate scaffold for admin/categories&#8230; The reason is that you&#8217;ll also get a model that is namespaced in admin (i.e. model would be Admin::Category). Scaffolded views also wouldn&#8217;t work as it seems that generator doesn&#8217;t take into account the fact that you are using a namespace.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://icebergist.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://icebergist.com/posts/restful-admin-namespaced-controller-using-scaffolding/feed</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>Mosso hosting cloud</title>
		<link>http://icebergist.com/posts/mosso-hosting-cloud</link>
		<comments>http://icebergist.com/posts/mosso-hosting-cloud#comments</comments>
		<pubDate>Wed, 17 Sep 2008 10:44:33 +0000</pubDate>
		<dc:creator>Slobodan Kovačević</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[cloud computing]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://icebergist.com/?p=13</guid>
		<description><![CDATA[Mosso&#8217;s hosting cloud at $100 / month seems like a good solution to get a scalable server. However one thing bugs me, actually two things&#8230; First one: they offer FTP only access. Meaning you cannot deploy sites directly from code repositories (i.e. git or svn). That sucks. Second thing that bugs me: for $100 you [...]]]></description>
			<content:encoded><![CDATA[<p><a class="external" href="http://www.mosso.com/">Mosso&#8217;s hosting cloud</a> at $100 / month seems like a good solution to get a scalable server. However one thing bugs me, actually two things&#8230;</p>
<p>First one: they offer <strong>FTP only access</strong>. Meaning you cannot deploy sites directly from code repositories (i.e. git or svn). That sucks.</p>
<p>Second thing that bugs me: for $100 you get quite a lot of computing power which can be used to run multiple sites &#8211; but <strong>you are only allowed to have one Rails app running</strong>. Only one. If you want additional Rails apps (for example to have a test server) you need to pay an extra fee.</p>
<p>I know it&#8217;s cloud computing and that you have to be able to run it with any additional configuration (that&#8217;s why I think it&#8217;s ok that you have to freeze your gems in Rails apps, because you cannot install any gems yourself)&#8230; but not being able to checkout my code from repository and having to upload the whole app each time you make changes <strong>is really annoying</strong>.</p>
<p>In their defense, the support guy said that they are working on it, but he could give me an ETA when they&#8217;ll allow something like that.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://icebergist.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://icebergist.com/posts/mosso-hosting-cloud/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Collection partial variable naming &#8211; new in edge rails</title>
		<link>http://icebergist.com/posts/collection-partial-variable-naming</link>
		<comments>http://icebergist.com/posts/collection-partial-variable-naming#comments</comments>
		<pubDate>Mon, 07 Jul 2008 21:41:41 +0000</pubDate>
		<dc:creator>Slobodan Kovačević</dc:creator>
				<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[edge]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://icebergist.com/?p=9</guid>
		<description><![CDATA[One thing that always annoyed me when rendering collection partials is that a local var in partial is named same as a partial template name. So, to go around this I always created another local variable in partial and gave it a more meaningful name. No longer&#8230; As the Ryan says from now on in [...]]]></description>
			<content:encoded><![CDATA[<p>One thing that always annoyed me when rendering collection partials is that a local var in partial is named same as a partial template name. So, to go around this I always created another local variable in partial and gave it a more meaningful name.</p>
<p>No longer&#8230; As the <a title="What's New in Edge Rails: Collection Partial Variable Naming " href="http://ryandaigle.com/articles/2008/7/7/what-s-new-in-edge-rails-collection-partial-variable-naming">Ryan says</a> from now on in the Edge Rails you can specify the name of the local variable in which each collection element will be exposed within a partial. You will can do this:</p>
<pre>render :partial =&gt; 'employees', :collection =&gt; @workers, :as =&gt; :person</pre>
<p>It&#8217;s a simple thing, but it&#8217;s just one of the things that bugged me. I am glad it&#8217;s gone now.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://icebergist.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://icebergist.com/posts/collection-partial-variable-naming/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SproutCore &#8211; a javascript framework</title>
		<link>http://icebergist.com/posts/sproutcore-javascript-framework</link>
		<comments>http://icebergist.com/posts/sproutcore-javascript-framework#comments</comments>
		<pubDate>Thu, 03 Jul 2008 21:54:11 +0000</pubDate>
		<dc:creator>Slobodan Kovačević</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Ruby and Rails]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://icebergist.com/?p=4</guid>
		<description><![CDATA[SproutCore is a javascript framework which tries to enable developers to build web apps that look and act more like a desktop apps. It steps away from a classic web app model by moving a lot of app into the browser itself, which then interacts with server via AJAX. As it says on the SproutCore [...]]]></description>
			<content:encoded><![CDATA[<p><a title="SproutCore - Javascript Framework" href="http://www.sproutcore.com">SproutCore</a> is a javascript framework which tries to enable developers to build web apps that look and act more like a desktop apps.</p>
<p>It steps away from a classic web app model by moving a lot of app into the browser itself, which then interacts with server via AJAX. As it says on the <a title="About SproutCore" href="http://www.sproutcore.com/about/">SproutCore site</a>:</p>
<blockquote><p>After lots of testing, we have found that the most efficient way to server a SproutCore application is as a …. static web page!</p></blockquote>
<p>This means that a &#8220;simple&#8221; static HTML page (which is easily served by Apache) makes browser do most of the work (i.e. server doesn&#8217;t have to generate the pages) which frees up server to respond only to AJAX initiated requests.</p>
<p><a title="SproutCore - Javascript Framework written in Ruby" href="http://www.sproutcore.com">SproutCore</a> is written in Ruby, but once you build the app it will generate a set of HTML, JS and CSS files, so you don&#8217;t need to know Ruby in order to use it. As the site says:</p>
<blockquote><p>The code you write with SproutCore will resemble a desktop app written in Cocoa more than it will a web application written in Rails.</p></blockquote>
<p><img class="alignright size-full wp-image-6" title="SproutCore Photos Demo" src="http://icebergist.com/wp-content/uploads/2008/07/sprout-photos-demo.jpg" alt="SproutCore Photos Demo Screenshot" width="500" height="236" />Another great thing about SproutCore is that it can be hooked up with any backend as long as it can communicate with it using HTTP. It can be anything: Rails, PHP, Perl, Java, ASP&#8230;</p>
<p>Actions speak louder than words, so take a look at the SproutCore demos which shows you exactly what it&#8217;s all about.</p>
<ul>
<li><a title="SproutCore demo photo gallery" href="http://www.sproutcore.com/static/photos/">SproutCore based photo gallery</a> &#8211; iPhoto anyone? <img src='http://icebergist.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li><a title="SproutCore demo sample controls" href="http://www.sproutcore.com/static/sample_controls/">SproutCore sample controls</a> &#8211; demonstrates what kind of controls are already available in SproutCore.</li>
</ul>
<p>In next few days I will try to build a sample application powered by SproutCore and Rails to see how it goes. I will post my impressions here. After all if it&#8217;s something Apple used for Mobile.me &#8211; well, it can&#8217;t be that bad. <img src='http://icebergist.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://icebergist.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://icebergist.com/posts/sproutcore-javascript-framework/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

