<?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>Lasse Bunk&#039;s weblog &#187; Ruby on Rails</title>
	<atom:link href="http://lassebunk.dk/tag/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://lassebunk.dk</link>
	<description>(Sorry, I don&#039;t have a tagline.)</description>
	<lastBuildDate>Wed, 01 Sep 2010 20:21:33 +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>Rails 3 and Bundler: Deploying gems using Capistrano</title>
		<link>http://lassebunk.dk/2010/09/01/rails-3-bundler-gems-capistrano/</link>
		<comments>http://lassebunk.dk/2010/09/01/rails-3-bundler-gems-capistrano/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 20:17:10 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[RubyGems]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=1283</guid>
		<description><![CDATA[I have previously described how to deploy gems using Capistrano in a Rails 2 application. After upgrading to Rails 3, this has changed a bit. Rails now uses Bundler for dependency management, so we need to use the bundle install command instead of rake gems:install.
In your deploy.rb:

after &#34;deploy:update_code&#34;, &#34;bundle:install&#34;

namespace :bundle do
  desc &#34;Bundle install&#34;
 [...]]]></description>
			<content:encoded><![CDATA[<p>I have previously described how to <a href="http://lassebunk.dk/2009/07/18/deploying-gems-using-capistrano/">deploy gems using Capistrano</a> in a Rails 2 application. After upgrading to Rails 3, this has changed a bit. Rails now uses <a href="http://gembundler.com/">Bundler</a> for dependency management, so we need to use the <code>bundle install</code> command instead of <code>rake gems:install</code>.</p>
<p>In your <code>deploy.rb</code>:</p>
<pre class="brush: ruby;">
after &quot;deploy:update_code&quot;, &quot;bundle:install&quot;

namespace :bundle do
  desc &quot;Bundle install&quot;
  task :install, :roles =&gt; :app do
    run &quot;cd #{current_release} &amp;&amp; #{sudo} bundle install&quot;
  end
end
</pre>
<p>It&#8217;s as easy as that. Let me know if you have any comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2010/09/01/rails-3-bundler-gems-capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mass-assigning protected attributes in Rails</title>
		<link>http://lassebunk.dk/2010/07/09/mass-assigning-protected-attributes-in-rails/</link>
		<comments>http://lassebunk.dk/2010/07/09/mass-assigning-protected-attributes-in-rails/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 14:28:37 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Attributes]]></category>
		<category><![CDATA[Mass-assignment]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=1240</guid>
		<description><![CDATA[Rails has a great feature called protected attributes which you can set like this:

class User &#60; ActiveRecord:Base
  attr_protected :account_id
end

Or you can use the inverted versions (which I prefer) where you set which attributes are accessible, like this:

attr_accessible :name, :email

What this does is that it tells Rails which attributes can be used in mass-assignment like [...]]]></description>
			<content:encoded><![CDATA[<p>Rails has a great feature called protected attributes which you can set like this:</p>
<pre class="brush: ruby;">
class User &lt; ActiveRecord:Base
  attr_protected :account_id
end
</pre>
<p>Or you can use the inverted versions (which I prefer) where you set which attributes are accessible, like this:</p>
<pre class="brush: ruby;">
attr_accessible :name, :email
</pre>
<p>What this does is that it tells Rails which attributes can be used in mass-assignment like this:</p>
<pre class="brush: ruby;">
User.create(:name =&gt; &quot;Lasse&quot;, :email =&gt; &quot;lassebunk@gmail.com&quot;)
</pre>
<p>or what&#8217;s used more:</p>
<pre class="brush: ruby;">
User.create(params[:user])
</pre>
<p>Then some malicious hacker cannot use mass-assignment to manually set the account_id.</p>
<p>If you try to assign to protected attributes you&#8217;ll get the following warning:</p>
<pre class="brush: bash;">WARNING: Can't mass-assign these protected attributes: account_id</pre>
<p>But the problem is: What if I&#8217;m no hacker, but I should have unlimited access, for example as an administrator? Then I can&#8217;t mass-assign to any protected attributes. Then I&#8217;d need to do something like this:</p>
<pre class="brush: ruby;">
u = User.new(params[:user])
u.account_id = params[:user][:account_id]
</pre>
<p>Not very pretty.</p>
<p>What I&#8217;ve done is that I&#8217;ve created an extension to some of the methods taking mass-assignment and added an optional parameter called <code>guard_protected_attributes</code> which has a default value of <code>true</code>.</p>
<p>Example:</p>
<pre class="brush: ruby;">
# config/initializers/unprotected_attributes.rb
class ActiveRecord::Base
  def update_attributes_with_unprotected(attributes, guard_protected_attributes = true)
    send :attributes=, attributes, guard_protected_attributes
    save
  end
  alias_method_chain :update_attributes, :unprotected
end
</pre>
<p>We can do this because the native <code>ActiveRecord::Base#attributes=</code> can also be called with <code>guard_unprotected_attributes</code>.</p>
<p>Now you can call <code>update_attributes</code> like this:</p>
<pre class="brush: ruby;">
user = User.find(3)
user.update_attributes(params[:user], false)
</pre>
<p>and it will also assign the protected attributes.</p>
<p>I have made extensions to <code>create</code>, <code>new</code>, <code>update_attributes</code>, and <code>update_attributes!</code>.</p>
<p>The ugly part, however, is that to make it work, I had to copy the functions in their entirety which could potentially mean that if you use it on a Rails version other than exactly 2.3.8 it might not work. Sorry for that.</p>
<p>You can download the extensions <a href="http://lassebunk.dk/downloads/unprotected_attributes.rb">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2010/07/09/mass-assigning-protected-attributes-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Outputting the flash to views and layouts</title>
		<link>http://lassebunk.dk/2010/03/05/outputting-the-flash-to-views-and-layouts/</link>
		<comments>http://lassebunk.dk/2010/03/05/outputting-the-flash-to-views-and-layouts/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 16:13:20 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Views]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=1177</guid>
		<description><![CDATA[Here is a simple way of outputting the first message in the flash (because I didn&#8217;t want it to output both flash[:error] and flash[:notice] at the same time).

# in the controller
flash[:notice] = &#34;Thanks for signing up!&#34;

.. and&#8230;

# in the view
&#60;% flash.detect do &#124;type, text&#124; %&#62;
	&#60;div id=&#34;flash&#34; class=&#34;&#60;%= type.to_s %&#62;&#34;&#62;
		&#60;%= text %&#62;
	&#60;/div&#62;
&#60;% end %&#62;

The detect method [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a simple way of outputting the first message in the <a href="http://api.rubyonrails.org/classes/ActionController/Flash.html">flash</a> (because I didn&#8217;t want it to output both <code>flash[:error]</code> and <code>flash[:notice]</code> at the same time).</p>
<pre class="brush: rails;">
# in the controller
flash[:notice] = &quot;Thanks for signing up!&quot;
</pre>
<p>.. and&#8230;</p>
<pre class="brush: rails;">
# in the view
&lt;% flash.detect do |type, text| %&gt;
	&lt;div id=&quot;flash&quot; class=&quot;&lt;%= type.to_s %&gt;&quot;&gt;
		&lt;%= text %&gt;
	&lt;/div&gt;
&lt;% end %&gt;
</pre>
<p>The <code>detect</code> method will return the first key/value pair of the flash where the block doesn&#8217;t return <code>false</code>. However, that&#8217;s not what we&#8217;re using it for – we&#8217;re using it to make sure we only get the first element.</p>
<p>Hope this is useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2010/03/05/outputting-the-flash-to-views-and-layouts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Sinatra to serve smaller (than Rails) applications</title>
		<link>http://lassebunk.dk/2010/02/25/using-sinatra-to-serve-smaller-than-rails-applications/</link>
		<comments>http://lassebunk.dk/2010/02/25/using-sinatra-to-serve-smaller-than-rails-applications/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 14:19:55 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Rack]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Sinatra]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=1147</guid>
		<description><![CDATA[So, maybe you&#8217;ve been coding Rails for a while and wondered &#8211; &#8220;do I really need this full stack framework to serve even small applications?&#8221;. Well, no you don&#8217;t :-)
Check out Norbauer&#8217;s DNS Tools (and on Github). It&#8217;s a small set of easy to use DNS tools. So small it would be overkill to serve [...]]]></description>
			<content:encoded><![CDATA[<p>So, maybe you&#8217;ve been coding <a href="http://rubyonrails.org">Rails</a> for a while and wondered &#8211; &#8220;do I really need this full stack framework to serve even small applications?&#8221;. Well, no you don&#8217;t :-)</p>
<p>Check out <a href="http://dns.norbauer.com">Norbauer&#8217;s DNS Tools</a> (and on <a href="http://github.com/norbauer/dns-tools">Github</a>). It&#8217;s a small set of easy to use DNS tools. So small it would be overkill to serve it using Rails.</p>
<p>Norbauer&#8217;s using <a href="http://www.sinatrarb.com/">Sinatra</a> to serve the app.</p>
<p>Start by installing the gem:</p>
<pre class="brush: bash;">
$ sudo gem install sinatra
</pre>
<p>After that it&#8217;s as simple as this:</p>
<pre class="brush: ruby;">
# myapp.rb
require 'rubygems'
require 'sinatra'

get '/' do
  &quot;Welcome to my homepage!&quot;
end

get '/contact' do
  &quot;My contact info is...&quot;
end
</pre>
<p>At your terminal:</p>
<pre class="brush: bash;">
$ ruby myapp.rb
== Sinatra/0.9.4 has taken the stage on 4567 for development with backup from Mongrel
</pre>
<p>Now you can view it in your browser at <a href="http://localhost:4567">http://localhost:4567</a> and <a href="http://localhost:4567/contact">http://localhost:4567/contact</a>. Simple.</p>
<p>This is great for hosting apps from your command line (for example check out <a href="http://adam.blog.heroku.com/past/2009/2/11/taps_for_easy_database_transfers/">Taps</a>) but what if you wanted to serve it like you would a Rails app?</p>
<p>Well, then you&#8217;d be using <a href="http://rack.rubyforge.org/">Rack</a>.</p>
<p>Create a file named <code>config.ru</code> in the same folder as <code>myapp.rb</code>:</p>
<pre class="brush: ruby;">
require 'myapp'
run Sinatra::Application
</pre>
<p>Now you can deploy your application as you would if it was written in Rails (thanks to <code>config.ru</code>).<br />
If you want to check this setup at your localhost, run the following:</p>
<pre class="brush: bash;">
$ sudo gem install rack # make sure you have Rack installed
$ rackup # run the Rack application using config.ru
</pre>
<p>It&#8217;s as easy as that! Great for hosting small applications.</p>
<p>Also see:</p>
<ul>
<li><a href="http://rack.rubyforge.org/doc/">List of Rack compliant web servers</a></li>
<li><a href="http://www.modrails.com/documentation/Users%20guide.html#_deploying_a_rack_based_ruby_application">Deploying a Rack-based Ruby application [with Phusion Passenger]</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2010/02/25/using-sinatra-to-serve-smaller-than-rails-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Paperclip and jpegcam to get pictures from your webcam into Rails</title>
		<link>http://lassebunk.dk/2010/02/18/paperclip-jpegcam-webcam-rails/</link>
		<comments>http://lassebunk.dk/2010/02/18/paperclip-jpegcam-webcam-rails/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 14:45:49 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jpegcam]]></category>
		<category><![CDATA[Paperclip]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Webcam]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=1096</guid>
		<description><![CDATA[Here&#8217;s how to get pictures from your webcam into Rails using the Paperclip plugin and jpegcam.
What we will do is create a Photo model and a Photos controller with actions new, upload and create to take care of the image creation.
Start by creating a new Rails application:

$ rails webcam_app
$ cd webcam_app

Create the Photo model:

$ script/generate [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s how to get pictures from your webcam into Rails using the <a href="http://github.com/thoughtbot/paperclip">Paperclip plugin</a> and <a href="http://code.google.com/p/jpegcam/">jpegcam</a>.</p>
<p>What we will do is create a <code>Photo</code> model and a <code>Photos</code> controller with actions <code>new</code>, <code>upload</code> and <code>create</code> to take care of the image creation.</p>
<p>Start by creating a new Rails application:</p>
<pre class="brush: bash;">
$ rails webcam_app
$ cd webcam_app
</pre>
<p>Create the <code>Photo</code> model:</p>
<pre class="brush: bash;">
$ script/generate model Photo description:string
$ rake db:migrate
</pre>
<p>Create the <code>Photos</code> controller:</p>
<pre class="brush: bash;">
$ script/generate controller Photos
</pre>
<p>Edit <code>config/routes.rb</code> to contain a photos resource:</p>
<pre class="brush: rails;">
map.resources :photos, :only =&gt; [:index, :show, :new, :create], :new =&gt; { :upload =&gt; :post }
</pre>
<p><a href="http://code.google.com/p/jpegcam/downloads/list">Download jpegcam</a> and put <code>webcam.js</code> in your <code>public/javascripts</code> folder and <code>webcam.swf</code> and <code>shutter.mp3</code> in your <code>public</code> folder.</p>
<p>Create the layout file <code>app/views/layouts/application.html.erb</code> and insert the following HTML:</p>
<pre class="brush: rails;">
&lt;html&gt;
  &lt;head&gt;
    &lt;%= javascript_include_tag :defaults %&gt;
    &lt;%= javascript_include_tag 'webcam' %&gt;
  &lt;/head&gt;
  &lt;body&gt;
	  &lt;%= yield %&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Next, create <code>app/views/photos/new.html.erb</code> and make a div for the webcam contents:</p>
<pre class="brush: html;">
&lt;div id=&quot;webcam&quot;&gt;&lt;/div&gt;
</pre>
<p>And the actual webcam javascript:</p>
<pre class="brush: html;">
&lt;script type=&quot;text/javascript&quot;&gt;
  webcam.set_swf_url('/webcam.swf');
  webcam.set_api_url('&lt;%= upload_new_photo_path %&gt;');
  webcam.set_quality(90);
  webcam.set_shutter_sound(true, '/shutter.mp3');
  $('webcam').innerHTML = webcam.get_html(640, 480);
&lt;/script&gt;
</pre>
<p>That will run the actual webcam so you can see yourself :) But for taking a picture, we&#8217;ll need to add the following button:</p>
<pre class="brush: html;">
&lt;input type=&quot;button&quot; value=&quot;Take picture&quot; onclick=&quot;webcam.snap();&quot; /&gt;
</pre>
<p>Now when you click the button, the webcam image will be posted to <code>/photos/new/upload</code>. Try it out:</p>
<pre class="brush: bash;">
$ script/server
</pre>
<p>and go to <a href="http://localhost:3000/photos/new">http://localhost:3000/photos/new</a>.</p>
<p>Let&#8217;s add some code for handling the upload.</p>
<p>The <code>webcam.swf</code> just uploads a bunch of jpeg data so we&#8217;ll need to get a hold of the raw post data. That&#8217;s done with Rails&#8217; <code>request.raw_post</code>. In your <code>PhotosController</code>:</p>
<pre class="brush: rails;">
def upload
  File.open(upload_path, 'w') do |f|
    f.write request.raw_post
  end
  render :text =&gt; &quot;ok&quot;
end

private

def upload_path # is used in upload and create
  file_name = session[:session_id].to_s + '.jpg'
  File.join(RAILS_ROOT, 'public', 'uploads', file_name)
end
</pre>
<p>Remember to create the <code>public/uploads</code> folder.</p>
<p>Now, back to <code>app/views/photos/new.html.erb</code>. Create the following at the bottom of the view:</p>
<pre class="brush: rails;">
&lt;% form_for Photo.new, :html =&gt; { :style =&gt; &quot;display: none;&quot; } do |f| %&gt;
  &lt;p&gt;
    &lt;%= f.label :description %&gt;&lt;br /&gt;
    &lt;%= f.text_field :description %&gt;
  &lt;/p&gt;
  &lt;p&gt;
    &lt;%= f.submit &quot;Save the photo&quot; %&gt;
    or &lt;%= link_to &quot;Take another&quot;, new_photo_path %&gt;
  &lt;/p&gt;
&lt;% end %&gt;
</pre>
<p>In your javascript just below the webcam div, insert the following function:</p>
<pre class="brush: javascript;">
function upload_complete(msg) {
  if (msg == 'ok') {
    $('new_photo').show();
    $('photo_description').focus();
  } else {
    alert('An error occured');
    webcam.reset();
  }
}
</pre>
<p>And add the following webcam code:</p>
<pre class="brush: javascript;">
webcam.set_hook('onComplete', 'upload_complete');
</pre>
<p>Now when you take a picture you will get a new photo form for entering a description. If something goes wrong, the webcam will be reset so you can try again. This might also be a good time to check your logs.</p>
<p>Now we have the upload (see for yourself in your public/uploads folder) but we still need to add Paperclip to the model.<br />
Start by installing the plugin:</p>
<pre class="brush: bash;">
$ script/plugin install git://github.com/thoughtbot/paperclip.git
</pre>
<p>In the <code>Photo</code> model:</p>
<pre class="brush: rails;">
class Photo &lt; ActiveRecord::Base
  has_attached_file :image, :styles =&gt; { :medium =&gt; &quot;300x300&gt;&quot;, :thumb =&gt; &quot;100x100&gt;&quot; }
end
</pre>
<p>For this to work, we need to add some necessary Paperclip columns to our <code>Photo</code> model:</p>
<pre class="brush: bash;">
$ script/generate paperclip photo image
$ rake db:migrate
</pre>
<p>Now we can show photos like this:</p>
<pre class="brush: rails;">
&lt;%= image_tag photo.image.url(:thumb) %&gt;
</pre>
<p>We just need to save the photos first. Add the following to your <code>PhotosController</code> somewhere above the <code>private</code> keyword:</p>
<pre class="brush: rails;">
def create
  @photo = Photo.new(params[:photo])
  @photo.image = File.new(upload_path)
  @photo.save

  redirect_to @photo
end

def show
  @photo = Photo.find(params[:id])
end

def index
  @photos = Photo.all
end
</pre>
<p>In <code>app/views/photos/show.html.erb</code>:</p>
<pre class="brush: rails;">
&lt;h1&gt;Photo&lt;/h1&gt;
&lt;p&gt;&lt;%= image_tag @photo.image.url(:medium) %&gt;&lt;/p&gt;
&lt;p&gt;
  &lt;strong&gt;Description:&lt;/strong&gt;&lt;br /&gt;
  &lt;%=h @photo.description %&gt;
&lt;/p&gt;
&lt;p&gt;
  &lt;%= link_to &quot;Take a new picture&quot;, new_photo_path %&gt;
  | &lt;%= link_to &quot;See all pictures&quot;, photos_path %&gt;
&lt;/p&gt;
</pre>
<p>And last but not least in <code>app/views/photos/index.html.erb</code>:</p>
<pre class="brush: rails;">
&lt;h1&gt;All photos&lt;/h1&gt;
&lt;p&gt;
  &lt;% @photos.each do |photo| %&gt;
    &lt;%= link_to image_tag(photo.image.url(:thumb)), photo %&gt;
  &lt;% end %&gt;
&lt;/p&gt;
&lt;p&gt;
  &lt;%= link_to &quot;Take a new picture&quot;, new_photo_path %&gt;
&lt;/p&gt;
</pre>
<p>Now start your <code>script/server</code> if it isn&#8217;t already, go to <a href="http://localhost:3000/photos">http://localhost:3000/photos</a> – aaannnd.. it works!</p>
]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2010/02/18/paperclip-jpegcam-webcam-rails/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Three months on the Mac stack</title>
		<link>http://lassebunk.dk/2009/09/24/three-months-on-the-mac-stack/</link>
		<comments>http://lassebunk.dk/2009/09/24/three-months-on-the-mac-stack/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 13:39:45 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Amiga]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[C64]]></category>
		<category><![CDATA[Compiler]]></category>
		<category><![CDATA[Github]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Migration]]></category>
		<category><![CDATA[Netbooks]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Slicehost]]></category>
		<category><![CDATA[Slices]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[TextMate]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[VMware Fusion]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=221</guid>
		<description><![CDATA[It’s actually four months now – since May 1st – but I’ve been wanting to write this article for a month. Hence the – somewhat misleading – title.
I bought my MacBook on May 1th after viewing a screencast where a guy sets up a blog in 15 minutes using Ruby on Rails. I immediately said [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">It’s actually four months now – since May 1st – but I’ve been wanting to write this article for a month. Hence the – somewhat misleading – title.</p>
<p>I bought my <a href="http://www.apple.com/macbook/">MacBook</a> on May 1th after viewing a <a href="http://rubyonrails.org/screencasts">screencast where a guy sets up a blog in 15 minutes</a> using <a href="http://rubyonrails.org">Ruby on Rails</a>. I immediately said to my stepdad: “I’m going to buy a Mac and learn Ruby on Rails!”</p>
<p>And so I did &#8211; the day after, I bought a Mac.</p>
<p>I’ve always been a dedicated user of <a href="http://www.microsoft.com">Microsoft</a>&#8217;s products. First <a href="http://en.wikipedia.org/wiki/Commodore_64">C64</a>, then <a href="http://en.wikipedia.org/wiki/Amiga">Amiga</a>, then <a href="http://en.wikipedia.org/wiki/Power_Macintosh_5300">Mac</a>, then PC. I liked the way everything was tested and came from one place, unlike <a href="http://en.wikipedia.org/wiki/Open_source">open source</a>. I’ve always been saying stuff like “I like to pay for my software because then I&#8217;m be sure about the quality.” – but in reality, everyone who uses Windows and other Microsoft products know that this isn’t always the case.</p>
<p>So I bought the Mac, and the first thing that surprised me, was how much of day-to-day work was done in the <a href="http://en.wikipedia.org/wiki/Apple_Terminal">Terminal</a>, or <a href="http://en.wikipedia.org/wiki/Command-line_interface">command line</a>. When I installed Ruby on Rails, it was via command line; when I installed plugins, it was via command line. Evererything command line. :-)</p>
<p>Over the next few days I began to get a hang of it. I bought a couple of <a href="http://en.wikipedia.org/wiki/Domain_name">domain names</a> and signed up for a <a href="http://en.wikipedia.org/wiki/Slice_%28disk%29">slice</a> at <a href="http://www.slicehost.com">Slicehost</a> – because I had read some <a href="http://railswork.com">job description</a> that said that you should&#8217;ve at least tried to use a whole day of setting a slice.</p>
<p>Coming from Windows, Linux is a whole other deal to setup. I used a lot of the <a href="http://articles.slicehost.com/">Slicehost articles</a> that guides you through the whole process from setup and security to getting your slice to run as a <a href="http://www.apache.org">webserver</a>.</p>
<p>In the beginning I was a little nervous about all the command lines, if they would really work and so one. But the more you try it, the more calm you get. It just works! And lucky me there was a lot of helpful articles about Unix and Linux commands out there (just search for the command on <a href="http://www.google.com">Google</a>).</p>
<p>Since starting out on the Mac, I’ve learned a multitude of things:</p>
<ul>
<li> Setting up an <a href="http://www.ubuntu.com/">Ubuntu</a> <a href="http://en.wikipedia.org/wiki/Slice_%28disk%29">slice</a> at <a href="http://www.slicehost.com">Slicehost</a>.</li>
<li>Setting up a <a href="http://www.apache.org">web server</a>.</li>
<li>Setting up <a href="http://www.ubuntu.com/GetUbuntu/download-netbook">Ubuntu Netbook Remix</a> on my <a href="http://eeepc.asus.com/">netbook</a>.</li>
<li>Setting up <a href="http://www.ubuntu.com/getubuntu/download-server">Ubuntu server</a> at home, also on my netbook – which now functions as my testing server.</li>
<li>Programming a little <a href="http://www.php.net">PHP</a> – see Tweet My Cam.</li>
<li>Programming <a href="http://rubyonrails.org">Ruby on Rails</a>.</li>
<li>Tweaking some <a href="http://www.java.com">Java</a> code, <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html">compiling</a> and <a href="http://forums.sun.com/thread.jspa?threadID=174214">signing</a> a <a href="http://en.wikipedia.org/wiki/Java_applet">java applet</a> in one day – see a demo <a href="http://lassebunk.dk/2009/07/19/using-the-clipboard-to-post-images/">here</a>.</li>
<li>Download and compile software (<a href="http://tldp.org/LDP/LG/current/smith.html">configure, make, make install</a>).</li>
<li><a href="http://railsontherun.com/2008/3/3/how-to-use-github-and-submit-a-patch">Submitted a patch</a> to a Ruby on Rails <a href="http://github.com/technoweenie/restful-authentication">plugin</a> on <a href="http://github.com">Github</a>.</li>
<li>Setting up <a href="http://wordpress.org">Wordpress</a> and <a href="http://mu.wordpress.org/">Wordpress Mu</a> blogs and making my own <a href="http://lassebunk.dk">theme</a> – see <a href="http://lassebunk.dk">my private blog</a> and <a href="http://userdriven.dk">private work blog</a>.</li>
<li>Setting up a <a href="http://subversion.tigris.org/">Subversion</a> repository at <a href="http://www.xp-dev.com/">XP-Dev.com</a>.</li>
<li>Using the Subversion repository :-)</li>
<li>Loving <a href="http://macromates.com/">Textmate</a> as my favorite editor – also over <a href="http://www.microsoft.com/visualstudio">Visual Studio</a>.</li>
<li>Plus a bunch of other things.</li>
</ul>
<p>In short I’ve learned so much about the open source world that just wasn’t that easy on the Microsoft platform.</p>
<p>I still use Microsoft Windows and other products, but now it’s through <a href="http://www.vmware.com/products/fusion/">VMware Fusion</a> on the Mac.</p>
<p>I’m happy about the Mac because <a href="http://www.apple.com/macosx/">OS X</a> is very unobtrusive, fast operating system and what it does, it does very good. But at the same time, I also want a netbook that’s easier to carry, so I may end up running both systems for different purposes (unless I&#8217;m just installing Ubuntu on the netbook too ;-)).</p>
<p>Hope you found this post interesting – I wrote it to tell about a beautiful (yak, I know) progress from Windows to Mac and Linux. Thumbs up if this has made you want to try it too. And please tell me in the comments. :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2009/09/24/three-months-on-the-mac-stack/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Deploying gems using Capistrano</title>
		<link>http://lassebunk.dk/2009/07/18/deploying-gems-using-capistrano/</link>
		<comments>http://lassebunk.dk/2009/07/18/deploying-gems-using-capistrano/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 17:19:32 +0000</pubDate>
		<dc:creator>lassebunk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Capistrano]]></category>
		<category><![CDATA[Gems]]></category>
		<category><![CDATA[Rake]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://lassebunk.dk/?p=137</guid>
		<description><![CDATA[Update for Rails 3: Rails 3 and Bundler: Deploying gems using Capistrano
Thought I&#8217;d share this because I had a lot of trouble figuring out how and where to run the &#8220;rake gems:install&#8221; when deploying with Capistrano. I wanted it to automatically deploy the gems when I call &#8220;cap deploy:migrations&#8221; &#8211; this is done by installing [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update for Rails 3:</strong> <a href="http://lassebunk.dk/2010/09/01/rails-3-bundler-gems-capistrano/">Rails 3 and Bundler: Deploying gems using Capistrano</a></p>
<p>Thought I&#8217;d share this because I had a lot of trouble figuring out how and where to run the <a href="http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies">&#8220;rake gems:install&#8221;</a> when deploying with <a href="http://www.capify.org">Capistrano</a>. I wanted it to automatically deploy the gems when I call &#8220;cap deploy:migrations&#8221; &#8211; this is done by installing the gems right after update_code, like this:</p>
<pre class="brush: ruby;">
# config/deploy.rb
after &quot;deploy:update_code&quot;, &quot;gems:install&quot;

namespace :gems do
  desc &quot;Install gems&quot;
  task :install, :roles =&gt; :app do
    run &quot;cd #{current_release} &amp;&amp; #{sudo} rake gems:install&quot;
  end
end
</pre>
<p>Some of the examples I&#8217;ve seen use &#8220;cd #{current_path}&#8221; but I don&#8217;t think this would work as the &#8220;current&#8221; symlink hasn&#8217;t been updated at the time the &#8220;update_code&#8221; task is run. That&#8217;s why I use &#8220;current_release&#8221;.</p>
<p>Also others use &#8220;rake RAILS_ENV=production gems:install&#8221; but I can&#8217;t see why you should have to use RAILS_ENV here. If I&#8217;m wrong, please correct me.</p>
<p>Some of the links I found when trying to get this to work:</p>
<ul>
<li><a href="http://capitate.rubyforge.org/recipes/deploy.html">Capistrano recipes: deploy</a></li>
<li><a href="http://henrik.nyh.se/2008/10/cap-gems-install-and-a-gem-dependency-gotcha">cap gems:install and a Gem dependency gotcha</a></li>
<li><a href="http://new.teabass.com/posts/install-required-gems-remotely-with-capistrano">Install required gems remotely with capistrano</a></li>
<li><a href="http://github.com/jamis/capistrano/blob/df0935c4c135207582da343aacdd4cf080fcfed0/lib/capistrano/recipes/deploy.rb">lib/capistrano/recipes/deploy.rb</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://lassebunk.dk/2009/07/18/deploying-gems-using-capistrano/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
