<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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" version="2.0">

<channel>
	<title>Jim Neath</title>
	
	<link>http://jimneath.org</link>
	<description>Ruby on Rails, Javascript, CSS and Standards</description>
	<pubDate>Thu, 19 Jun 2008 13:23:56 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/JimNeath" type="application/rss+xml" /><item>
		<title>Using jQuery with Ruby on Rails</title>
		<link>http://jimneath.org/2008/06/18/using-jquery-with-ruby-on-rails/</link>
		<comments>http://jimneath.org/2008/06/18/using-jquery-with-ruby-on-rails/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 12:54:03 +0000</pubDate>
		<dc:creator>Jim Neath</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[jrails]]></category>

		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://jimneath.org/?p=43</guid>
		<description><![CDATA[By default, Rails comes packed with the Prototype javascript library and the effects library, Scriptaculous. While this is all well and good sometimes you want a change. I personally prefer jQuery to prototype. I don&#8217;t have any beef with prototype, infact I used it for about a year before even getting into rails, but I [...]]]></description>
			<content:encoded><![CDATA[<p>By default, Rails comes packed with the <a href="http://www.prototypejs.org">Prototype</a> javascript library and the effects library, <a href="http://script.aculo.us">Scriptaculous</a>. While this is all well and good sometimes you want a change. I personally prefer <a href="http://www.jquery.com">jQuery</a> to prototype. I don&#8217;t have any beef with prototype, infact I used it for about a year before even getting into rails, but I just prefer the jQuery syntax and selectors.</p>
<h4>jQuery</h4>
<blockquote><p>jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.</p></blockquote>
<p>jQuery, like Protoype, is a javascript library that takes care of much of the grunt work you face day to day. It helps to resolve your cross browser issues, makes creating dom elements easier and various other things.</p>
<h4>Some Prototype / jQuery Examples</h4>
<p>I&#8217;ll post a couple of code examples so you can see the difference in the libraries. I&#8217;m not saying these examples are the best way to do things (I know people will say otherwise), they&#8217;re just here to help you understand the libraries.</p>
<p><strong>Note:</strong> I haven&#8217;t tested these examples, although I believe they should all work.</p>
<h5>Open all links marked with rel=&#8221;external&#8221; in new windows</h5>
<p><strong>Prototype</strong></p>
<pre><code class="javascript">document.observe('dom:loaded', function() {
  $$('a[rel~=external]&#8216;).invoke(&#8217;writeAttribute&#8217;, &#8216;target&#8217;, &#8216;blank&#8217;);
});</code></pre>
<p><strong>jQuery</strong></p>
<pre><code class="javascript">$(function() {
  $('a[rel=external]&#8216;).attr(&#8217;target&#8217;, &#8216;blank&#8217;);
});</code></pre>
<h5>Changes class of a div on click of an element</h5>
<p><strong>Prototype</strong></p>
<pre><code class="javascript">$('the-link').observe('click', function() {
  $('the-div').addClass('hello');
});</code></pre>
<p><strong>jQuery</strong></p>
<pre><code class="javascript">$('#the-link').click( function() {
  $('#the-div').addClass('hello');
});</code></pre>
<p>For more information on jQuery syntax and all the bells and whistles, have a look at the <a href="http://docs.jquery.com/Main_Page">jQuery Documentation</a>.</p>
<h4>More Prototype <=> jQuery Examples</h4>
<p><a href="http://remysharp.com/">Remy Sharp</a> has also published a walk through comparison between Prototype and jQuery to help developers go from one language to another.</p>
<div style="text-align:center;margin-bottom:10px;">
<object width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=prototype-jquery-going-from-one-to-the-other-1193346036472971-5"/><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=prototype-jquery-going-from-one-to-the-other-1193346036472971-5" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
</div>
<h4>Hello, jRails!</h4>
<p>Want to use jQuery but love your prototype helpers too much? Fear not! Enter jRails, stage left.</p>
<blockquote><p>jRails is a drop-in jQuery replacement for Prototype/script.aculo.us on Rails. Using jRails, you can get all of the same default Rails helpers for javascript functionality using the lighter jQuery library. </p></blockquote>
<p>That basically says it all. </p>
<h5>Installing jRails</h5>
<pre><code>ruby script/plugin install http://ennerchi.googlecode.com/svn/trunk/plugins/jrails</code></pre>
<p>Bosh. All sorted. The plugin will install all the required javascript files over to <code>public/javascripts</code>. Unless you&#8217;re planning on using prototype along side jQuery you will probably want to delete the prototype files in your javascripts folder.</p>
<h5>Including jQuery and Friends</h5>
<p>Now you want to open up your <code>application.html.erb</code> file and edit the javascript include tag:</p>
<pre><code class="ruby">&lt;%= javascript_include_tag :defaults %&gt;</code></pre>
<p>This will now include all the jRails files instead of the prototype/script.aculo.us files. You might want to just include the files that you need instead of all these:</p>
<pre><code class="ruby">&lt;%= javascript_include_tag 'jquery' %&gt;
&lt;%= javascript_include_tag 'jquery-ui' %&gt;
&lt;%= javascript_include_tag 'jrails' %&gt;</code></pre>
<h4>Using jQuery in RJS</h4>
<p>You don&#8217;t have to do anything. Brilliant. That&#8217;s the main point of the jRails plugin. It does all the grunt work for you. Just use your helpers as you normally would.</p>
<p>I will say one thing though: a lot of the time you may just find it easier to use <code>page <<</code> at certain times:</p>
<pre><code class="ruby">page << "$('span#bacon').text('CHunKy');"</code></pre>
<h4>jQuery UI</h4>
<blockquote><p>jQuery UI provides abstractions for low-level interaction and high-level, themeable widgets, built on top of the jQuery JavaScript Library, that you can use to build highly interactive web applications.</p>
<p>The core of the library revolves around different mouse interactions, namely drag and dropping, sorting, selecting, and resizing, as well as a powerful set of effects.</p>
<p>On top of the core interactions are built a number of reusable widgets, including accordions, date pickers, dialogs, sliders and tabs.</p></blockquote>
<p>I was going to write some blurb about jQuery UI but I feel that this quote says it all, really. Want to know more? Check out the <a href="http://ui.jquery.com/">jQuery UI site</a></p>
<h4>Some jQuery Scripts</h4>
<p>I thought I&#8217;d list a couple of helpful scripts to help you on your way to the wonderful world of jQuery. So here goes:</p>
<h5><a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" target="blank">Validation</a></h5>
<p>Validation is a great form validation script by Jörn Zaefferer. Unobtrusive, sexy and just plain brilliant.</p>
<h5><a href="http://leandrovieira.com/projects/jquery/lightbox/" target="blank">Lightbox</a></h5>
<blockquote><p>jQuery lightBox plugin is simple, elegant, unobtrusive, no need extra markup and is used to overlay images on the current page through the power and flexibility of jQuery´s selector.</p>
<p>lightBox is a plugin for jQuery. It was inspired in Lightbox JS by Lokesh Dhakar.</p>
<p>The better way to know what is jQuery lightBox plugin, click the Example tab above and see it in action.</p></blockquote>
<p>Everybody loves a lightbox, surely? The jQuery Lightbox script is based on  by Leandro Vieira Pinho.</p>
<p>If you have any other suggestions for great jQuery scripts, let me know and I&#8217;ll add them to the list.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimneath.org/2008/06/18/using-jquery-with-ruby-on-rails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Converting Videos with Rails: Converting the Video</title>
		<link>http://jimneath.org/2008/06/03/converting-videos-with-rails-converting-the-video/</link>
		<comments>http://jimneath.org/2008/06/03/converting-videos-with-rails-converting-the-video/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 13:22:29 +0000</pubDate>
		<dc:creator>Jim Neath</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[acts_as_state_machine]]></category>

		<category><![CDATA[FFMPEG]]></category>

		<category><![CDATA[paperclip]]></category>

		<category><![CDATA[rails]]></category>

		<category><![CDATA[video conversion]]></category>

		<guid isPermaLink="false">http://jimneath.org/?p=40</guid>
		<description><![CDATA[So you&#8217;ve installed FFMPEG. Now it&#8217;s time to move onto converting the video. For this we&#8217;re going to be using a couple of plugins.
Paperclip
We will be using the paperclip plugin to upload the videos onto our server. Details of how to install paperclip can be found in my previous article: Paperclip: Attaching Files in Rails. [...]]]></description>
			<content:encoded><![CDATA[<p>So you&#8217;ve <a href="http://jimneath.org/2008/06/02/converting-videos-with-rails-installing-ffmpeg/">installed FFMPEG</a>. Now it&#8217;s time to move onto converting the video. For this we&#8217;re going to be using a couple of plugins.</p>
<h4>Paperclip</h4>
<p>We will be using the paperclip plugin to upload the videos onto our server. Details of how to install paperclip can be found in my previous article: <a href="http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/">Paperclip: Attaching Files in Rails</a>. To install you can use any of the following:</p>
<pre><code>git://github.com/thoughtbot/paperclip.git # Github
https://svn.thoughtbot.com/plugins/paperclip/trunk/ # SVN
http://rubyforge.org/projects/paperclip/ # Gem version</code></pre>
<h4>Acts As State Machine</h4>
<p>Acts_as_state_machine allows you to turn your model into a <a href="http://en.wikipedia.org/wiki/State_machine">Finite State Machine</a> (FSM). </p>
<blockquote><p>A finite state machine (FSM) or finite state automaton (plural: automata) or simply a state machine, is a model of behavior composed of a finite number of states, transitions between those states, and actions. A finite state machine is an abstract model of a machine with a primitive internal memory.</p></blockquote>
<p>So let&#8217;s install acts_as_state_machine:</p>
<pre><code>ruby script/plugin install http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk/ acts_as_state_machine</code></pre>
<h4>Creating the Model</h4>
<p>First off, let&#8217;s create our video model. We&#8217;ll call it <code>video</code>. Inventive, eh?</p>
<pre><code>ruby script/generate model video</code></pre>
<p>Open up your new video model and let&#8217;s edit it to look like this:</p>
<pre><code class="ruby">class Video < ActiveRecord::Base
  # Paperclip
  # http://www.thoughtbot.com/projects/paperclip
  has_attached_file :source

  # Paperclip Validations
  validates_attachment_presence :source
  validates_attachment_content_type :source, :content_type => &#8216;video/quicktime&#8217;
end</code></pre>
<p>Nothing spectacular. If you&#8217;ve used Paperclip before then nothing should surprise you here. The <code>has_attached_file :source</code> line tells our model that it has an uploaded file called source. This is where we will be storing our video files. The rest of the file uses the built in Paperclip validations.</p>
<h4>Adding States</h4>
<p>Underneath your current model content, we want to add the following:</p>
<pre><code class="ruby">  # Acts as State Machine
  # http://elitists.textdriven.com/svn/plugins/acts_as_state_machine
  acts_as_state_machine :initial => :pending
  state :pending
  state :converting
  state :converted, :enter => :set_new_filename
  state :error

  event :convert do
    transitions :from => :pending, :to => :converting
  end

  event :converted do
    transitions :from => :converting, :to => :converted
  end

  event :failed do
    transitions :from => :converting, :to => :error
  end</code></pre>
<p>This will setup acts_as_state_machine along with the states and transitions we want to use. It&#8217;s all pretty simple.</p>
<h4>Run the Migrations</h4>
<p>Open up the <code>xxx_create_videos.rb</code> migration file and edit it so it looks like the following:</p>
<pre><code class="ruby">class CreateVideos < ActiveRecord::Migration
  def self.up
    create_table :videos do |t|
      t.string :source_content_type
      t.string :source_file_name
      t.integer :source_file_size
      t.string :state
      t.timestamps
    end
  end

  def self.down
    drop_table :videos
  end
end</code></pre>
<p>The columns starting with <code>:source_</code> are all files for Paperclip. The <code>:state</code> column is used with <code>acts_as_state_machine</code>.</p>
<p>Run the migrations:</p>
<pre><code>rake db:migrate</code></pre>
<h4>Adding the Conversion Methods</h4>
<p>In your video.rb file add the following methods to your model. These methods take care of the converting the video file:</p>
<pre><code class="ruby">  # This method is called from the controller and takes care of the converting
  def convert
    self.convert!
    success = system(convert_command)
    if success &#038;&#038; $?.exitstatus == 0
      self.converted!
    else
      self.failure!
    end
  end

  protected

  # This method creates the ffmpeg command that we'll be using
  def convert_command
    flv = File.join(File.dirname(source.path), "#{id}.flv")
    File.open(flv, 'w')

    command = <<-end_command
      ffmpeg -i #{ source.path }  -ar 22050 -ab 32 -acodec mp3
      -s 480x360 -vcodec flv -r 25 -qscale 8 -f flv -y #{ flv }
    end_command
    command.gsub!(/\s+/, " ")
  end

  # This update the stored filename with the new flash video file
  def set_new_filename
    update_attribute(:source_file_name, "#{id}.flv")
  end</code></pre>
<h4>The Controller</h4>
<p>I&#8217;m not going to post the views in this article as they should be straight forward. Just make sure to add <code>:multipart => true</code> to your form otherwise your file&#8217;s won&#8217;t be uploaded and you&#8217;ll look stupid.</p>
<pre><code class="ruby">class VideosController < ApplicationController
  def index
    @videos = Video.find :all
  end

  def new
    @video = Video.new
  end

  def create
    @video = Video.new(params[:video])
    if @video.save
      @video.convert
      flash[:notice] = 'Video has been uploaded'
      redirect_to :action => &#8216;index&#8217;
    else
      render :action => &#8216;new&#8217;
    end
  end

  def show
    @video = Video.find(params[:id])
  end
end
</code></pre>
<p>After the video is saved in the create method, the convert method is called. This should convert the video to a flash video file, update the database entry and set the state of the model. The state will be set to <code>converted</code> if everything went to plan, or <code>error</code> if everything went to shit.</p>
<p>You can view the full source of video.rb <a href="http://jimneath.org/wp-content/uploads/2008/06/videorb.txt">here</a>.</p>
<h4>Displaying the Video in a View</h4>
<p>When you want to display the video in a view, you will need two things. The first, is <a href="http://blog.deconcept.com/swfobject/">swfobject</a>, an unobtrusive way to include flash into a page. </p>
<blockquote><p>SWFObject is a small Javascript file used for embedding Adobe Flash content. The script can detect the Flash plug-in in all major web browsers (on Mac and PC) and is designed to make embedding Flash movies as easy as possible. It is also very search engine friendly, degrades gracefully, can be used in valid HTML and XHTML 1.0 documents*, and is forward compatible, so it should work for years to come.</p></blockquote>
<p>The second is a flash video player. I highly suggest <a href="http://www.jeroenwijering.com/?item=JW_FLV_Media_Player">JW FLV Media Player</a>.</p>
<blockquote><p>The JW FLV Media Player (built with Adobe&#8217;s Flash) is an easy and flexible way to add video and audio to your website. It supports playback of any format the Adobe Flash Player can handle (FLV, but also MP3, H264, SWF, JPG, PNG and GIF). It also supports RTMP and HTTP (Lighttpd) streaming, RSS, XSPF and ASX playlists, a wide range of flashvars (variables), an extensive  javascript API and accessibility features.</p></blockquote>
<p>Make sure you include the <code>swfobject.js</code> file on the page you wish to display your video on:</p>
<pre><code class="ruby"><%= javascript_include_tag 'swfobject' %></code></pre>
<p>Next, copy the <code>mediaplayer.swf</code> to <code>public/flash/mediaplayer.swf</code></p>
<pre><code class="html">&lt;div id="player"&gt;
  You need to have &lt;%= link_to 'Flash Player', 'http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' %&gt; installed to display this video
&lt;/div&gt;

&lt;script type="text/javascript"&gt;
  var so = new SWFObject('/flash/mediaplayer.swf', 'mpl', '480', '360', '8');
  so.addParam('allowscriptaccess', 'always');
  so.addParam('allowfullscreen', 'true');
  so.addVariable('height', '360');
  so.addVariable('width', '480');
  so.addVariable('file', '&lt;%= @video.source.url %&gt;');
  so.write('player');
&lt;/script&gt;</code></pre>
<p>The contents of the div will be replaced with the flash player, if flash isn&#8217;t installed the user is shown a message with a link to download flash player. The <code><%= @video.source.url %></code> line will output the path to the flv video file.</p>
<p>There&#8217;s a setup wizard on the JW FLV Player site located <a href="http://www.jeroenwijering.com/?page=wizard">here</a>.</p>
<h4>Final Note</h4>
<p>You shouldn&#8217;t really be converting videos with the user request. You should be using a background worker to do it for you. I&#8217;ll be showing you how to do this in the next article in this series.</p>
<p>Give it a whirl. As far as I know it should work fine. I&#8217;ve tested it on my local host and it seems to work. Admittedly, there should be a lot more error checking and whatnot, but for a simple example I think it does the job.</p>
<p>If you have any suggestions, improvements etc that I could incorporate into this article then leave a comment and I&#8217;ll sort it out.</p>
<h4>More In This Series</h4>
<ul>
<li><a href="http://jimneath.org/2008/06/02/converting-videos-with-rails-installing-ffmpeg/">Converting Videos with Rails: Installing FFMPEG</a></li>
<li><a href="http://jimneath.org/2008/06/03/converting-videos-with-rails-converting-the-video/">Converting Videos with Rails: How to Convert Videos</a></li>
<li>Converting Videos with Rails: Using Background Processes</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jimneath.org/2008/06/03/converting-videos-with-rails-converting-the-video/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Converting Videos with Rails: Installing FFMPEG</title>
		<link>http://jimneath.org/2008/06/02/converting-videos-with-rails-installing-ffmpeg/</link>
		<comments>http://jimneath.org/2008/06/02/converting-videos-with-rails-installing-ffmpeg/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 09:59:21 +0000</pubDate>
		<dc:creator>Jim Neath</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[FFMPEG]]></category>

		<category><![CDATA[rails]]></category>

		<category><![CDATA[ubuntu]]></category>

		<category><![CDATA[video conversion]]></category>

		<guid isPermaLink="false">http://jimneath.org/?p=39</guid>
		<description><![CDATA[This is the first of a three part series covering how to convert videos using the marvellous FFMPEG library. Video converison is a must have if you are planning on creating a social network site.
In this part I&#8217;ll be covering how to install FFMPEG on Ubuntu Hardy Heron (8.04).
Install FFMPEG Dependencing
First off, you need to [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first of a three part series covering how to convert videos using the marvellous <a href="http://ffmpeg.mplayerhq.hu/">FFMPEG</a> library. Video converison is a must have if you are planning on <a href="http://jimneath.org/2008/04/25/building-a-social-network-site-in-rails/">creating a social network site</a>.</p>
<p>In this part I&#8217;ll be covering how to install FFMPEG on <a href="http://www.ubuntu.com/">Ubuntu</a> Hardy Heron (8.04).</p>
<h4>Install FFMPEG Dependencing</h4>
<p>First off, you need to download and install the dependency packages for FFMPEG. Without these, it&#8217;ll all go tits. So it&#8217;s a good thing to sort out.</p>
<pre><code>sudo apt-get install build-essential subversion libx264-dev libdts-dev libswscale-dev liblame-dev libfaad2-dev libfaac-dev libxvidcore4-dev liba52-0.7.4 liba52-0.7.4-dev </code></pre>
<p>The lib* files help you to convert various video formats into flash videos, or which ever format you wish. Subversion is needed so you can download the FFMPEG source.</p>
<h4>Check Out FFMPEG Source</h4>
<p>Next, you need to checkout the current FFMPEG source from subversion. So let&#8217;s do that:</p>
<pre><code>mkdir src
cd src
svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
cd ffmpeg</code></pre>
<p>Bosh! We now have the FFMPEG source on our server. So far so good.</p>
<h4>Compiling FFMPEG</h4>
<p>Now we&#8217;re ready to compile to beast. Make sure you&#8217;re in the ffmpeg directory that we just downloaded. Then run the configure command:</p>
<pre><code>./configure --enable-gpl --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-liba52 --enable-libdc1394 --enable-libgsm --enable-libfaad --enable-libfaac --enable-libxvid --enable-pthreads --enable-libx264 --enable-shared--enable-postproc --enable-avfilter-lavf --enable-swscale --enable-avfilter </code></pre>
<p>Then we&#8217;re ready to compile:</p>
<pre><code>make
sudo make install</code></pre>
<p>This will take ages. So don&#8217;t worry if it seems to be going on for a while. The last time I did it, it took about 5 minutes or so.</p>
<p>Hopefully, once that&#8217;s finished, you should be ready to rock.</p>
<h4>Testing FFMPEG</h4>
<p>Now, hold your breath and type:</p>
<pre><code>ffmpeg -v</code></pre>
<p>You should now get a load of blurb along the lines of:</p>
<pre><code>jim@jim-ubuntu:~$ ffmpeg -v
FFmpeg version SVN-r13207, Copyright (c) 2000-2008 Fabrice Bellard, et al.
  configuration: --enable-gpl --enable-libvorbis --enable-libtheora --enable-liba52 --enable-libdc1394 --enable-libgsm --enable-libmp3lame --enable-libfaad --enable-libfaac --enable-libxvid --enable-pthreads --enable-libx264 --enable-shared --enable-swscale --enable-avfilter --enable-postproc --enable-avfilter-lavf
  libavutil version: 49.6.0
  libavcodec version: 51.57.0
  libavformat version: 52.13.0
  libavdevice version: 52.0.0
  libavfilter version: 0.0.0
  built on May 21 2008 11:55:20, gcc: 4.2.3 (Ubuntu 4.2.3-2ubuntu7)
ffmpeg: missing argument for option '-v'</code></pre>
<p>If you don&#8217;t get anything similiar to the above, then you&#8217;ve fucked it. Check the FFMPEG docs or post here and I&#8217;ll try and help you out.</p>
<h4>More In This Series</h4>
<ul>
<li><a href="http://jimneath.org/2008/06/02/converting-videos-with-rails-installing-ffmpeg/">Converting Videos with Rails: Installing FFMPEG</a></li>
<li><a href="http://jimneath.org/2008/06/03/converting-videos-with-rails-converting-the-video/">Converting Videos with Rails: How to Convert Videos</a></li>
<li>Converting Videos with Rails: Using Background Processes</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jimneath.org/2008/06/02/converting-videos-with-rails-installing-ffmpeg/feed/</wfw:commentRss>
		</item>
		<item>
		<title>SWFUpload, Paperclip and Ruby on Rails</title>
		<link>http://jimneath.org/2008/05/15/swfupload-paperclip-and-ruby-on-rails/</link>
		<comments>http://jimneath.org/2008/05/15/swfupload-paperclip-and-ruby-on-rails/#comments</comments>
		<pubDate>Thu, 15 May 2008 12:49:47 +0000</pubDate>
		<dc:creator>Jim Neath</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[Flash]]></category>

		<category><![CDATA[SWFUpload]]></category>

		<category><![CDATA[Upload]]></category>

		<guid isPermaLink="false">http://jimneath.org/?p=23</guid>
		<description><![CDATA[Edit: Added paperclip validations to photo model. Fixed a bug with the js (thanks to Kevin). Commented the js file and added all methods used by SWFUPload.
SWFUpload
SWFUpload is a small JavaScript/Flash library to get the best of both worlds. It features the great upload capabilities of Flash and the accessibility and ease of HTML/CSS.
SWFUpload is [...]]]></description>
			<content:encoded><![CDATA[<p><em>Edit: Added paperclip validations to photo model. Fixed a bug with the js (thanks to <a href="http://www.mpet45.co.uk/">Kevin</a>). Commented the js file and added all methods used by SWFUPload.</em></p>
<h4><a href="http://www.swfupload.org">SWFUpload</a></h4>
<blockquote><p>SWFUpload is a small JavaScript/Flash library to get the best of both worlds. It features the great upload capabilities of Flash and the accessibility and ease of HTML/CSS.</p></blockquote>
<p><a href="http://www.swfupload.org">SWFUpload</a> is a brilliant tool built with flash and javascript that allows you to upload multiple files at the same time, allows you to display progress bars and various other useful things. The front end is left wide open by the SWFUpload API so it gives you complete control over how the UI works.</p>
<h4><a href="http://www.thoughtbot.com/projects/paperclip">Paperclip</a></h4>
<p>As many of you might have realised, I love <a href="http://www.thoughtbot.com/projects/paperclip">Paperclip</a>. It&#8217;s a great plugin that takes care of all the grunt work and lets you get on with other stuff. I&#8217;ve covered <a href="http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/">how to use Paperclip</a> before.</p>
<h4>Making Rails Play Nice with SWFUpload</h4>
<p>There are a couple of pitfalls when using SWFUpload with your projects. I&#8217;ve covered them below:</p>
<h5>Scrambled Mime Types</h5>
<p>This is an annoying problem caused by the upload facility in Flash. It basically means that all the files you upload via SWFUpload have the content type of <code>application/octet-stream</code>, which in most cases isn&#8217;t what you want.</p>
<p>To fix this you will want to use the <a href="http://mime-types.rubyforge.org/">Mime-Types gem</a>. To Install, simply do the following:</p>
<pre><code class="ruby">gem install mime-types</code></pre>
<p>Now that you&#8217;ve got the mime types gem installed remember to require it somewhere in your code:</p>
<pre><code class="ruby">require 'mime/types'</code></pre>
<p>The way I&#8217;ve used it in the test project at the bottom is instead of assigning files to a model via <code>@photo.file = params[:photo][:file]</code>, I&#8217;ve created a custom method that fixes the mime type then passes the file to the correct method.</p>
<pre><code class="ruby"># Fix the mime types. Make sure to require the mime-types gem
def swfupload_file=(data)
  data.content_type = MIME::Types.type_for(data.original_filename).to_s
  self.file = data
end</code></pre>
<p>This takes care of the first problem.</p>
<h5>Problems with Sessions</h5>
<p>Flash has problems dealing with Rails sessions so a couple of quick fixes are needed. The first is to hack the sessions class. The fix can be found <a href="http://pastie.caboo.se/178902">here</a>.</p>
<p>I&#8217;ve included that code into a file called <code>swfupload_fix.rb</code> and placed it inside my initializers folder, so it&#8217;s loaded by the app is started.</p>
<p>Next add the following to your controller that handles the uploads:</p>
<pre><code class="ruby">session :cookie_only => false, :only => :create</code></pre>
<h5>The Controller</h5>
<p>By default, SWFUpload passes the post variable of <code>Filedata</code> when uploading. This can be changed easily if needed. The way I&#8217;ve dealt with the uploading in the test application is as follows:</p>
<pre><code class="ruby">def create
  # SWFUpload file
  if params[:Filedata]
    @photo = Photo.new(:swfupload_file => params[:Filedata])
    if @photo.save
      render :partial => &#8216;photo&#8217;, :object => @photo
    else
      render :text => &#8220;error&#8221;
    end
  else
    # Standard upload
    @photo = Photo.new params[:photo]
    if @photo.save
      flash[:notice] = &#8216;Your photo has been uploaded!&#8217;
      redirect_to photos_path
    else
      render :action => :new
    end
  end
end</code></pre>
<p>There&#8217;s probably a better way to do it, but for an example it shows you to logics of everything.</p>
<h5>Linux and Flash Upload Progress</h5>
<p>As Tim mentions in the <a href="http://jimneath.org/2008/05/15/swfupload-paperclip-and-ruby-on-rails/#comment-202">comments</a> there is a problem with displaying upload progress in Flash for Linux. It is covered around the net and alos mentioned in the <a href="http://demo.swfupload.org/Documentation/#uploadProgress">documentation for SWFUpload</a>:</p>
<blockquote><p>The uploadProgress event is fired periodically by the Flash Control. This event is useful for providing UI updates on the page.</p>
<p><strong>Note:</strong> The Linux Flash Player fires a single uploadProgress event after the entire file has been uploaded. This is a bug in the Linux Flash Player that we cannot work around.</p></blockquote>
<p>So basically it&#8217;s boned on linux and there&#8217;s nothing you can do about it.</p>
<h4>SWFUpload and Paperclip App</h4>
<p>Hopefully, this should get you on your way to using SWFUpload with Paperclip in Rails. However, I&#8217;ve created a small app that should help you on your way to getting things working. If you have any problems or find any thing that could be done better, let me know and I&#8217;ll fix them up.</p>
<p>It has been tested on Firefox 2.0, Safari 3.1.1 and IE 7 on Windoze Vista. Not tested on IE 6 because, quite frankly, it can fuck right off.</p>
<p>To try the app: unzip the file, change to the swfupload directory then run the following:</p>
<pre><code>rake db:migrate
ruby script/server</code></pre>
<p>Then you should be able to see it by visiting <a href="http://localhost:3000">http://localhost:3000</a>.</p>
<div class="download">
<a href='http://jimneath.org/wp-content/uploads/2008/05/swfupload1.zip'>SWFUpload Test Project</a></p>
<p>A test project to show how to get Ruby on Rails, SWFUpload and Paperclip to play together nicely.</p>
</div>
<p>You can also grab the example application from github:
<pre><code>git://github.com/JimNeath/swfupload---paperclip-example-app.git</code></pre>
<h4>Credit Where Credits Due</h4>
<p>A lot of places helped be get my head around this stuff. So A massive thanks to Andy Stewart over at <a href="http://blog.airbladesoftware.com/">Air Blade Software</a> and <a href="http://www.digitaria.com/">Dylan Vaughn</a>.</p>
<h4>More Resources</h4>
<ul>
<li><a href="http://demo.swfupload.org/Documentation/">SWFUpload API Documentation</a></li>
<li><a href="http://code.google.com/p/activeupload/">ActiveUpload - A plugin that facilitates the use of SWFUpload</a></li>
<li><a href="http://www.vimeo.com/906589">SWFUpload + attachment_fu + restful_authentication + amazon s3 + rails 2 = hard, but doable.</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jimneath.org/2008/05/15/swfupload-paperclip-and-ruby-on-rails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>More Usable Forms</title>
		<link>http://jimneath.org/2008/05/12/more-usable-forms/</link>
		<comments>http://jimneath.org/2008/05/12/more-usable-forms/#comments</comments>
		<pubDate>Mon, 12 May 2008 15:50:36 +0000</pubDate>
		<dc:creator>Jim Neath</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Forms]]></category>

		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://jimneath.org/?p=24</guid>
		<description><![CDATA[I just thought I&#8217;d post about a few things that you should be doing with your forms and also a few things I just like to do.
Use Labels
I still don&#8217;t understand why there are a load of people who don&#8217;t use labels within their forms. They&#8217;re more semantic that using strong tags like alot of [...]]]></description>
			<content:encoded><![CDATA[<p>I just thought I&#8217;d post about a few things that you should be doing with your forms and also a few things I just like to do.</p>
<h4>Use Labels</h4>
<p>I still don&#8217;t understand why there are a load of people who don&#8217;t use labels within their forms. They&#8217;re more semantic that using <code>strong</code> tags like alot of people seem to do. They&#8217;re also more user friendly. Also they&#8217;re useful for styling your forms.</p>
<blockquote><p>The LABEL element may be used to attach information to controls. Each LABEL element is associated with exactly one form control.</p></blockquote>
<p>And here&#8217;s how you&#8217;d use it in your code:</p>
<pre><code class="html">&lt;label for="username"&gt;Username&lt;/label&gt;
&lt;input type="text" name="username" id="username" /&gt;</code></pre>
<p>Which gives you:</p>
<p><a href='http://jimneath.org/wp-content/uploads/2008/05/basic-label.png'><img src="http://jimneath.org/wp-content/uploads/2008/05/basic-label.png" alt="" title="basic-label" width="226" height="32" class="aligncenter size-full wp-image-27" /></a></p>
<p>Now, when a user clicks on the label it will focus on the form item specified by the <code>for</code> attribute. Hooray.</p>
<h4>User the Pointer Cursor</h4>
<p>Here&#8217;s the CSS:</p>
<pre><code class="css">label, button, input.button
{
    cursor: pointer;
}</code></pre>
<p>Easy. It does require you to add a class to submit and reset buttons, but hey it&#8217;s a small sacrifice.</p>
<h4>Focus on the First Field</h4>
<p>Having to click on the first form field I want to fill in is a pain in the ass. Don&#8217;t make me do it. Here&#8217;s a quick jQuery function to do it for you:</p>
<pre><code class="javascript">$(document).ready(function() {
    $('input[type=text]:first&#8217;).focus();
});</code></pre>
<h4>No Confusing Buttons</h4>
<p>If you have a submit button and a reset button, or anything similiar, make sure people can tell the difference. I don&#8217;t want to fill in your huge form and then find I&#8217;ve accidentally clicked the reset button instead of the submit button.</p>
<p>An example is shown below:</p>
<p><a href='http://jimneath.org/wp-content/uploads/2008/05/buttons.png'><img src="http://jimneath.org/wp-content/uploads/2008/05/buttons.png" alt="" title="buttons" class="alignnone size-fullwp-image-29" /></a></p>
<p>Submit buttons on the left and sub actions on the right, see:</p>
<blockquote><p>Always put the Submit Form button on the left and on the Clear Form button on the right. Never, ever put the Submit Form button on the right and the Clear form button on the left.</p></blockquote>
<p>See?</p>
<p>I&#8217;ll post more when as they come to me, in my bizarre usability dreams. Feel free to post your own tips. Or to tell me that I know nothing at all about anything.</p>
<h4>More Reading</h4>
<ul>
<li><a href="http://www.keyrelevance.com/articles/usability-tips.htm">HighRankings Forum: Collected Web Site Usability Tips</a></li>
<li><a href="http://www.seoconsultants.com/html/forms/labels/">Usability Features - The Label Element</a></li>
<li><a href="http://webdesign.about.com/od/forms/a/aa050707.htm">What Makes a Web Form Usable or Unusable</a></li>
<li><a href="http://www.sitepoint.com/article/steps-useable-forms">7 Steps to Useable Forms</a></li>
<li><a href="http://www.alistapart.com/articles/sensibleforms">Sensible Forms: A Form Usability Checklist</a></li>
<li><a href="http://mattobee.com/blog/article/qa-checklist-online-forms/">QA Checklist: Form Usability</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jimneath.org/2008/05/12/more-usable-forms/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using Capistrano with Passenger (mod_rails)</title>
		<link>http://jimneath.org/2008/05/10/using-capistrano-with-passenger-mod_rails/</link>
		<comments>http://jimneath.org/2008/05/10/using-capistrano-with-passenger-mod_rails/#comments</comments>
		<pubDate>Sat, 10 May 2008 09:40:26 +0000</pubDate>
		<dc:creator>Jim Neath</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[capistrano]]></category>

		<category><![CDATA[mod_rails]]></category>

		<category><![CDATA[passenger]]></category>

		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://jimneath.org/?p=26</guid>
		<description><![CDATA[I love Phusion Passenger. It takes away most of the pain from deploying. Instead of having to mess around with lengthy apache config files, you can just upload. POW!
Phusion Passenger — a.k.a. mod_rails — makes deployment of applications built on the revolutionary Ruby on Rails web framework a breeze. It follows the usual Ruby on [...]]]></description>
			<content:encoded><![CDATA[<p>I love <a href="http://www.modrails.com/">Phusion Passenger</a>. It takes away most of the pain from deploying. Instead of having to mess around with lengthy apache config files, you can just upload. POW!</p>
<blockquote><p>Phusion Passenger — a.k.a. mod_rails — makes deployment of applications built on the revolutionary Ruby on Rails web framework a breeze. It follows the usual Ruby on Rails conventions, such as “Don’t-Repeat-Yourself”.</p></blockquote>
<h4>Installing Passenger</h4>
<p>Another great thing about Passenger is that it&#8217;s stupidly easy to install.</p>
<pre><code class="ruby">gem install passenger
passenger-install-apache2-module</code></pre>
<p>Then just follow the instructions that are displayed inside the terminal. It shouldn&#8217;t take more than 5-10 minutes max to get this shit on the road.</p>
<h4>Passenger Meet Capistrano</h4>
<p>You are using <a href="http://www.capify.org">capistrano</a>, aren&#8217;t you? Capistrano is a great tool, by <a href="http://weblog.jamisbuck.org/">Jamis Buck</a>, for deploying your applications. It takes all the monotonous stuff and does it for you, which is nice.</p>
<p>If you&#8217;re not using capistrano, you can install it with the following:</p>
<pre><code class="ruby">gem install capistrano</code></pre>
<p>Next, go to the root directory of your application and type:</p>
<pre><code class="ruby">capify .</code></pre>
<p>This will set up your application for use with capistrano by creating a deploy.rb  file and a Capfile. The deploy file is a recipe that will be used every time you deploy your application. Now lets look at making capistrano play with passenger.</p>
<h4>The Deploy Recipe</h4>
<p>I must confess something at this point: I&#8217;ve not actually tested this recipe yet as I&#8217;ve not had time. As far as I&#8217;m concerned it should work. If you find any problems let me know and I&#8217;ll fix them.</p>
<pre><code class="ruby">#############################################################
#	Application
#############################################################

set :application, "example"
set :deploy_to, "/var/www/#{application}"

#############################################################
#	Settings
#############################################################

default_run_options[:pty] = true
set :use_sudo, true

#############################################################
#	Servers
#############################################################

set :user, &#8220;jim&#8221;
set :domain, &#8220;example.com&#8221;
server domain, :app, :web
role :db, domain, :primary => true

#############################################################
#	Subversion
#############################################################

set :repository,  &#8220;http://www.example.com/svn/example&#8221;
set :svn_username, &#8220;jim&#8221;
set :svn_password, &#8220;password&#8221;
set :checkout, &#8220;export&#8221;

#############################################################
#	Passenger
#############################################################

namespace :passenger do
  desc &#8220;Restart Application&#8221;
  task :restart do
    run &#8220;touch #{current_path}/tmp/restart.txt&#8221;
  end
end

after :deploy, &#8220;passenger:restart&#8221;</code></pre>
<p>From what I&#8217;ve <a href="http://www.modrails.com/documentation/Users%20guide.html#_redeploying_restarting_the_ruby_on_rails_application">read</a>, the last few lines are all you should need to restart your application. This will be called after all deploy calls so you shouldn&#8217;t have to worry about anything.</p>
<p>Long live passenger</p>
<h4>Some Stuff to Read</h4>
<p>Here&#8217;s a list of a few things that are worth reading regarding capistrano and/or passenger.</p>
<h5>Capistrano</h5>
<ul>
<li><a href="http://capify.org/getting-started/basics">Getting Started with Capistrano</a></li>
<li><a href="http://weblog.jamisbuck.org/2008/5/2/capistrano-2-3-0">Capistrano 2.3.0 Released</a></li>
<li><a href="http://www.viget.com/extend/building-an-environment-from-scratch-with-capistrano-2/">Building an Environment From Scratch With Capistrano 2</a></li>
</ul>
<h5>Passenger (mod_rails)</h5>
<ul>
<li><a href="http://www.modrails.com/">Passenger Home Page</a></li>
<li><a href="http://www.modrails.com/documentation/Users%20guide.html">Passenger Documentation</a></li>
<li><a href="http://izumi.plan99.net/blog/index.php/2008/03/31/benchmark-passenger-mod_rails-vs-mongrel-vs-thin/">Benchmark: Passenger (mod_rails) vs Mongrel vs Thin</a></li>
<li><a href="http://benr75.com/articles/2008/04/12/setup-mod_rails-phusion-mac-os-x-leopard">Setup mod_rails Passenger Mac OS X Leopard</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jimneath.org/2008/05/10/using-capistrano-with-passenger-mod_rails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Building a Social Network Site in Rails</title>
		<link>http://jimneath.org/2008/04/25/building-a-social-network-site-in-rails/</link>
		<comments>http://jimneath.org/2008/04/25/building-a-social-network-site-in-rails/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 11:00:47 +0000</pubDate>
		<dc:creator>Jim Neath</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[FFMPEG]]></category>

		<category><![CDATA[Plugins]]></category>

		<category><![CDATA[rails]]></category>

		<category><![CDATA[Social Network]]></category>

		<category><![CDATA[SWFUpload]]></category>

		<guid isPermaLink="false">http://jimneath.org/?p=11</guid>
		<description><![CDATA[I&#8217;m not going to cover how to actually code an entire social network site in rails as all social network sites vary in their functionality (and it&#8217;ll take too long). I will cover plugins and other things you might find useful though.
Quick Start
If you don&#8217;t really want to do the coding but want to get [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not going to cover how to actually code an entire social network site in rails as all social network sites vary in their functionality (and it&#8217;ll take too long). I will cover plugins and other things you might find useful though.</p>
<h4>Quick Start</h4>
<p>If you don&#8217;t really want to do the coding but want to get a site up and running and soon as possible, you may want to have a look at <a href="http://lovdbyless.com/" target="_blank">Lovd by Less</a> by the guys over at <a href="http://lesseverything.com/" target="_blank">Less Everything</a>. Lovd by Less contains user signups, galleries, blogs, comments and various other things that you might want, so it&#8217;s a great starting block for your site.</p>
<h4>Social Network Plugins</h4>
<p>Here&#8217;s a list of plugins that I&#8217;ve found to be useful while coding my own social networking site:</p>
<h5><a href="http://weblog.techno-weenie.net/2006/8/1/restful-authentication-plugin" target="_blank">Restful Authentication</a></h5>
<p>RESTful Authentication is pretty much the defacto standard for user authentication in rails. It allows easily set up user signups, login functionality and email notifications. The plugin doesn&#8217;t set up thing&#8217;s like forgotten password functionality but there is <a href="http://www.railsforum.com/viewtopic.php?id=14216" target="_blank">a great tutorial</a> over Rails Forum.</p>
<pre><code class="ruby"># To Install
ruby script/plugin source http://svn.techno-weenie.net/projects/plugins
ruby script/plugin install restful_authentication</code></pre>
<h5><a href="http://www.thoughtbot.com/projects/paperclip" target="_blank">Paperclip</a></h5>
<p>Paperclip is a brilliant plugin by Jon Yurek over at <a href="http://www.thoughtbot.com" target="_blank">ThoughtBot</a>. Paperclip is used for managing file uploads and attaching the files to models. You can read more over at my article: <a href="http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/" target="_blank">Paperclip: Attaching Files in Rails</a>.</p>
<pre><code class="ruby"># To Install
svn export https://svn.thoughtbot.com/plugins/paperclip/tags/rel_2-0-2
piston import https://svn.thoughtbot.com/plugins/paperclip/trunk</code></pre>
<h5><a href="http://errtheblog.com/posts/56-im-paginating-again" target="_blank">Will_paginate</a></h5>
<p>Will paginate is a great plugin for allowing paging of your records. Paging is a pain in the ass, but will_paginate makes it easy as pie.</p>
<pre><code class="ruby"># To Install
ruby script/plugin install svn://errtheblog.com/svn/plugins/will_paginate</code></pre>
<h5><a href="http://code.dunae.ca/acts_as_slugable/README" target="_blank">Acts_as_slugable</a></h5>
<p>Acts_as_slugable takes the pain out of generating URL slugs. Everyone prefers meaningful URLs, so instead of showing a users page with &#8216;/users/231&#8242;, you can use &#8216;/users/jim-neath&#8217;. Nice.</p>
<pre><code class="ruby"># To Install
ruby script/plugin install http://code.dunae.ca/acts_as_slugable</code></pre>
<h5><a href="http://weblog.techno-weenie.net/2006/9/3/white-listing-plugin-for-rails" target="_blank">White_list</a></h5>
<p>White_list is yet another brilliant from Techno Weenie. The white_list helper will html encode all tags and strip all attributes that aren&#8217;t specifically allowed. It also strips href/src tags with invalid protocols, like javascript: especially.  It does its best to counter any tricks that hackers may use, like throwing in unicode/ascii/hex values to get past the javascript: filters.</p>
<pre><code class="ruby"># To Install
ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/white_list/</code></pre>
<h5><a href="http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/" target="_blank">Acts_as_commentable</a></h5>
<p>Acts_as_commentable allows you to add comments to your models. It takes care of all the polymorphic associations for you, which is nice.</p>
<pre><code class="ruby"># To Install
ruby script/plugin install http://juixe.com/svn/acts_as_commentable</code></pre>
<h5><a href="http://ambethia.com/recaptcha/" target="_blank">ReCAPTCHA</a></h5>
<p>Fucking captchas. Unfortunately a necessary evil. If you&#8217;re going to use captchas then you might as well help to digitalise books. The reCAPTCHA plugin utilises the <a href="http://recaptcha.net" target="_blank">reCAPTCHA</a> service which digitalises books by making users input the text.</p>
<pre><code class="ruby"># To Install
ruby script/plugin install svn.ambethia.com/pub/rails/plugins/recaptcha/</code></pre>
<h5><a href="http://agilewebdevelopment.com/plugins/acts_as_taggable_on_steroids" target="_blank">Acts_as_taggable_on_steroids</a></h5>
<p>Everybody loves tagging, surely? Tag pictures, videos, blog posts, whatever you want. Acts_as_taggable_on_steroids is a great plugin for allowing your users to tag their stuff. It allows tag clouds and all that web 2.0 jazz everyone seems to love.</p>
<pre><code class="ruby"># To Install
ruby script/plugin install http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids</code></pre>
<h5><a href="http://svn.rubyonrails.org/rails/plugins/exception_notification/README" target="_blank">Exception Notifier</a></h5>
<p>Exception Notifier is a must have. It emails you when your live application fails. No matter how much testing you do, no doubt there&#8217;s going to be a scenario where it fails and when that happens you want to know.</p>
<pre><code class="ruby"># To Install
ruby script/plugin install exception_notification</code></pre>
<h5><a href="http://blog.kabisa.nl/2008/02/05/rails-plugin-throttler/" target="_blank">Throttler</a></h5>
<p>This is one of my favourite plugins. Say your site get&#8217;s slashdotted of dugg and you end up with immense traffic, the main thing is to keep your site up and running. This is where throttler comes in. You can throttle certain actions on your site when your server load is above a certain level. So you could disable video uploads while your server load is above x to prevent your server from crumbling.</p>
<pre><code class="ruby"># To Install
ruby script/plugin install http://svn.kabisa.nl/rails/plugins/throttler</code></pre>
<h5><a href="http://shanti.railsblog.com/backup-fu-makes-amazon-s3-backups-redonkulous">Backup_fu</a></h5>
<p>You&#8217;ve been working on your social network site for months and finally the traffic is coming in and you have a decent user base. Then one day your server dies and you lose all your data. Woe is you. You should have backed up. Using Backup_fu you can automatically backup your database and files to Amazon S3.</p>
<pre><code class="ruby"># To Install
sudo gem install aws-s3
ruby script/plugin install http://backup-fu.googlecode.com/svn/backup_fu/</code></pre>
<h5><a href="http://www.danielfischer.com/2008/03/14/are-we-fischy-friends/" target="_blank">Fischy Friends</a></h5>
<p>Fischy_friends is a plugin by Daniel Fischer. It&#8217;s a great starting point for a friends system. I&#8217;ve used it on a couple of my own projects and it&#8217;s worked great for me.</p>
<pre># Github
http://github.com/dfischer/fischyfriends/tree/master</pre>
<h4>Other Useful Tools</h4>
<h5><a href="http://www.swfupload.org" target="_blank">SWFUpload</a></h5>
<p>I love SWFUpload. It uses a small flash file to allow users to upload multiple files at once. The front end is completely open and coded in javascript so you can customise it how you like. You can <a href="http://demo.swfupload.org/" target="_blank">see the demos here</a>.</p>
<p>Download: <a href="http://swfupload.googlecode.com/files/SWFUpload%20v2.0.2.Release.zip" target="_blank">http://swfupload.googlecode.com/files/SWFUpload%20v2.0.2.Release.zip</a></p>
<h5><a href="http://tinymce.moxiecode.com/" target="_blank">TinyMCE Text Editor</a></h5>
<p>TinyMCE is WYSIWYG editor coded entirely in javascript. It&#8217;s useful for the less techno savvy of your users (which will no doubt be most). There&#8217;s a whole load of plugins available for the editor so it&#8217;s highly extensible.</p>
<p>Download: <a href="http://prdownloads.sourceforge.net/tinymce/tinymce_3_0_7.zip?download" target="_blank">http://prdownloads.sourceforge.net/tinymce/tinymce_3_0_7.zip?download</a></p>
<h5><a href="http://ffmpeg.mplayerhq.hu/" target="_blank">FFMPEG/Mencoder</a></h5>
<p>FFMPEG is a command line utility to convert various formats of video into other formats. The main use you&#8217;ll want to use this for is to convert videos into flv files for use with a flash video player.</p>
<ul>
<li><a href="http://jimneath.org/2008/06/02/converting-videos-with-rails-installing-ffmpeg/">How to Install FFMPEG</a></li>
<li><a href="http://jimneath.org/2008/06/03/converting-videos-with-rails-converting-the-video/">Converting Videos with Rails and FFMPEG</a></li>
</ul>
<h5><a href="http://www.jeroenwijering.com/?item=JW_FLV_Player" target="_blank">JW FLV Media Player</a></h5>
<p>The JW FLV Media Player (built with <a href="http://www.adobe.com/products/flash/">Adobe&#8217;s Flash</a>) is an easy and flexible way to add video and audio to your website. It supports playback of any format the <a title="the Flash Player" href="http://www.adobe.com/products/flashplayer/">Adobe Flash Player</a> can handle (FLV, but also MP3, H264, SWF, JPG, PNG and GIF). It also supports RTMP and HTTP (Lighttpd) streaming, RSS, XSPF and ASX <a href="http://www.jeroenwijering.com/?item=Supported_Playlists">playlists</a>, a wide range of <a href="http://www.jeroenwijering.com/?item=Supported_Flashvars">flashvars</a> (variables), an extensive <a title="an overview of all available javascript interaction" href="http://www.jeroenwijering.com/?item=Javascript_interaction"> javascript API</a> and <a title="How to embed captions and an MP3 audiodescription to the FLV player" href="http://www.jeroenwijering.com/?item=Making_Video_Accessible">accessibility</a> features.</p>
<h4>Rails Hosting</h4>
<p>Once you&#8217;ve got your wonderful social network finished, you&#8217;re going to want somewhere to host the beast.</p>
<p>I highly recommend checking out <a href="http://www.brightbox.co.uk/a/ztpwh">Brightbox</a> for all your hosting needs. They offer affordable servers complete with <a href="http://www.fiveruns.com">Five Runs</a>.</p>
<h4>Books</h4>
<h5><a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.co.uk%2FRailsspace-Building-Networking-Addison-Wesley-Professional%2Fdp%2F0321480791%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1209116263%26sr%3D8-1&amp;tag=jimnearaidev-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325">RailsSpace: Building a Social Networking Website with Ruby on Rails</a><img style="border:none !important; margin:0px !important;" src="http://www.assoc-amazon.com/e/ir?t=jimnearaidev-20&amp;l=ur2&amp;o=1" border="0" alt="" width="1" height="1" /></h5>
<p><a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.co.uk%2FRailsspace-Building-Networking-Addison-Wesley-Professional%2Fdp%2F0321480791%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1209116263%26sr%3D8-1&amp;tag=jimnearaidev-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325"><img src="http://jimneath.org/wp-content/uploads/2008/06/51w2gz6rlnl_sl500_aa240_.jpg" alt="" title="51w2gz6rlnl_sl500_aa240_" width="240" height="240" class="alignleft size-medium wp-image-45" /></a></p>
<p>&#8220;Ruby on Rails is fast displacing PHP, ASP, and J2EE as the development framework of choice for discriminating programmers, thanks to its elegant design and emphasis on practical results. RailsSpace teaches you to build large-scale projects with Rails by developing a real-world application: a social networking website like MySpace, Facebook, or Friendster.</p>
<p>Inside, the authors walk you step by step from the creation of the site&#8217;s virtually static front page, through user registration and authentication, and into a highly dynamic site, complete with user profiles, image upload, email, blogs, full-text and geographical search, and a friendship request system. In the process, you learn how Rails helps you control code complexity with the model-view-controller (MVC) architecture, abstraction layers, automated testing, and code refactoring, allowing you to scale up to a large project even with a small number of developers.</p>
<p>This essential introduction to Rails provides</p>
<ul>
<li>A tutorial approach that allows you to experience Rails as it is actually used</li>
<li>A solid foundation for creating any login-based website in Rails</li>
<li>Coverage of newer and more advanced Rails features, such as form generators, REST, and Ajax (including RJS)</li>
<li>A thorough and integrated introduction to automated testing</li>
</ul>
<p>The book&#8217;s companion website provides the application source code, a blog with follow-up articles, narrated screencasts, and a working version of the RailSpace social network.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://jimneath.org/2008/04/25/building-a-social-network-site-in-rails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adobe AIR Free PDF Download</title>
		<link>http://jimneath.org/2008/04/18/adobe-air-free-pdf-download/</link>
		<comments>http://jimneath.org/2008/04/18/adobe-air-free-pdf-download/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 09:49:46 +0000</pubDate>
		<dc:creator>Jim Neath</dc:creator>
		
		<category><![CDATA[Free Stuff]]></category>

		<category><![CDATA[Adobe]]></category>

		<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://jimneath.org/?p=7</guid>
		<description><![CDATA[I honestly don&#8217;t know the first thing about AIR. I&#8217;m an AIR-dunce. Adobe to the rescue! POW!
Adobe are offering the updated PDF version of Adobe AIR for JavaScript Developers (Pocketguide) under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 license (someones made that up).
You can download the free PDF here. Kudos to Adobe and the AIR team [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jimneath.org/wp-content/uploads/2008/04/adobeairlogo.jpg"><img class="alignleft size-medium wp-image-8" style="float: left;" title="adobeairlogo" src="http://jimneath.org/wp-content/uploads/2008/04/adobeairlogo-300x158.jpg" alt="" width="300" height="158" /></a>I honestly don&#8217;t know the first thing about AIR. I&#8217;m an AIR-dunce. Adobe to the rescue! POW!</p>
<p>Adobe are offering the updated PDF version of <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FAdobe-JavaScript-Developers-Pocket-Guides%2Fdp%2F0596518374%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1208511521%26sr%3D8-1&amp;tag=jimnearaidev-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325">Adobe AIR for JavaScript Developers (Pocketguide)</a><img style="border:none !important; margin:0px !important;" src="http://www.assoc-amazon.com/e/ir?t=jimnearaidev-20&amp;l=ur2&amp;o=1" border="0" alt="" width="1" height="1" /> under a Creative <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" target="_blank">Commons Attribution-Noncommercial-Share Alike 3.0</a> license (someones made that up).</p>
<p>You can download the free PDF <a href="http://onair.adobe.com/files/AIRforJSDevPocketGuide.pdf?sdid=CEYFA">here</a>. Kudos to Adobe and the AIR team for being awesome bastards.</p>
<p><em>Credit: This was originally posted over at <a href="http://ajaxian.com/archives/adobe-air-for-javascript-developers-pocketguide" target="_blank">Ajaxian</a> so credit goes to them for a great find.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://jimneath.org/2008/04/18/adobe-air-free-pdf-download/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Paperclip: Attaching Files in Rails</title>
		<link>http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/</link>
		<comments>http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 14:03:59 +0000</pubDate>
		<dc:creator>Jim Neath</dc:creator>
		
		<category><![CDATA[Ruby on Rails]]></category>

		<category><![CDATA[paperlip]]></category>

		<category><![CDATA[rails]]></category>

		<category><![CDATA[uploads]]></category>

		<guid isPermaLink="false">http://jimneath.org/?p=5</guid>
		<description><![CDATA[Edit: Added paperclip validations
Paperclip is an awesome rails plugin by Jon Yurek at Thoughtbot. It is one of many plugins currently available that cater for file uploading and thumbnailing (see: Attachment_fu, file_column, etc). Now a quick quote from Jon:
For some reason, file attachment is annoying. I don’t know why, and I know a lot of [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Edit:</strong> Added paperclip validations</em></p>
<p><a href="http://www.thoughtbot.com/projects/paperclip" target="_blank">Paperclip</a> is an awesome rails plugin by Jon Yurek at <a href="http://www.thoughtbot.com/" target="_blank">Thoughtbot</a>. It is one of many plugins currently available that cater for file uploading and thumbnailing (see: <a href="http://svn.techno-weenie.net/projects/plugins/attachment_fu/" target="_blank">Attachment_fu</a>, file_column, etc). Now a quick quote from Jon:</p>
<blockquote><p>For some reason, file attachment is annoying. I don’t know why, and I know a lot of people have attempted to solve the problem in the past, myself included. Yet it still is. Having gotten fed up with gotchas and design decisions that we didn’t agree with, I went and wrote <a href="http://www.flickr.com/photos/kylemacdonald/395376506/">Paperclip</a> on the plane to <a href="http://en.oreilly.com/rails2008/public/content/home">RailsConf</a> last year. We’ve been using it here in various forms since and <span class="caps">IMHO</span> it’s <em>the</em> way to handle uploads, and finally decided that it should be released.</p></blockquote>
<h4>Installing Paperclip</h4>
<p>You can install Paperclip using a variety of different methods:</p>
<pre><code>svn export https://svn.thoughtbot.com/plugins/paperclip/tags/rel_2-0-2
piston import https://svn.thoughtbot.com/plugins/paperclip/trunk
</code></pre>
<p>You can also grab Paperclip from the <a href="http://github.com/thoughtbot/paperclip/tree/master" target="_blank">git repository</a>.</p>
<p><em>Quick Note: If you&#8217;re a windows user, you&#8217;re going to need to go for the trunk version as this contains a fix to a problem that basically meant that Paperclip borked.</em></p>
<h4>Basic Usage</h4>
<pre><code class="ruby">class User &lt; ActiveRecord::Base
  # Paperclip
  has_attached_file :photo,
    :styles =&gt; {
      :thumb=&gt; "100x100#",
      :small  =&gt; "150x150&gt;" }
end</code></pre>
<p>Attached files don&#8217;t need to have a seperare model (thank god). Your attachments are treated just like any other atribute. Images aren&#8217;t saved until your model is saved. There are a lot of bonus options but I&#8217;ll cover them towards the end of the article.</p>
<pre><code class="ruby">class AddPhotoToUser &lt; ActiveRecord::Migration
  def self.up
    add_column :users, :photo_file_name, :string # Original filename
    add_column :users, :photo_content_type, :string # Mime type
    add_column :users, :photo_file_size, :integer # File size in bytes
  end

  def self.down
    remove_column :users, :photo_file_name
    remove_column :users, :photo_content_type
    remove_column :users, :photo_file_size
  end
end</code></pre>
<p>Don&#8217;t forget to add these columns! Otherwise you&#8217;ll end up scratching your head and wondering where the hell you went wrong. The first part of the column names is the same as whatever you&#8217;re called your attached file. In our case that&#8217;s <em>photo</em>. Now update your database:</p>
<pre><code>rake db:migrate</code></pre>
<p>Now that your database is sorted, we can start working on adding some content. In your view you can add a file field like you would normally:</p>
<pre><code class="ruby">&lt;% form_for :user, :html =&gt; { :multipart =&gt; true } do |f| %&gt;
  &lt;%= f.file_field :photo%&gt;
&lt;% end %&gt;</code></pre>
<p>Don&#8217;t forget the <code>:multipart =&gt; true</code> part or everything will fail. Then you will cry.</p>
<p>Now in your controller, you don&#8217;t need to do a thing (hooray).</p>
<pre><code class="ruby">def create
  @user = User.create(params[:user])
end</code></pre>
<p>You should now be able to upload user photos to your hearts content.</p>
<p>To display your user&#8217;s photos all you need to do is call:</p>
<pre><code class="ruby">&lt;%= image_tag @user.photo.url %&gt;
&lt;%= image_tag @user.photo.url(:thumb) %&gt;</code></pre>
<p>The first call will display the original image. The second one will display the thumbnail image. Easy, yes?</p>
<h4>Paperclip Validations</h4>
<p>At the moment Paperclip has two different validation types, <code>validates_attachment_presence</code> and <code>validates_attachment_content_type</code>.</p>
<h5>validates_attachment_presence</h5>
<p><code>validates_attachment_presence<code> gives your ActiveRecord style validations to check to see if your paperclip model has an attachment present.</p>
<pre><code class="ruby">validates_attachment_presence :avatar</code></pre>
<h5>validates_attachment_content_type</h5>
<p><code>validates_attachment_content_type<code> lets your check the type of file that has been uploaded by checking it's mime type.</p>
<pre><code class="ruby">validates_attachment_content_type :avatar, :content_type => 'image/jpeg'</code></pre>
<h4>Paperclip Options</h4>
<p>Now that you&#8217;ve seen how easy to use and awesome Paperclip is, let&#8217;s have a look at some of the additional settings you can use:</p>
<pre><code class="ruby">has_attached_file :photo, :url =&gt; "/:class/:attachment/:id/:style_</code>:basename.:extension<code class="ruby">"</code></pre>
<p>Using <code>:url</code> you set when your images can be accessed from. The above setting would mean that your files are located at URLs similiar to <em>/user/photo/1/thumb_originalfilename.jpg&#8221;</em></p>
<pre><code class="ruby">has_attached_file :photo, :default_url =&gt; "/:class/:attachment/missing_:style.png"</code></pre>
<p>The <code>:default_url</code> option is used if there is no attached file for a model. If a user doesn&#8217;t have any uploaded avatar you could use this option to set a default avatar to show.</p>
<pre><code class="ruby">has_attached_file :photo, :styles =&gt; { :normal =&gt; "100x100#", :small =&gt; ["70x70&gt;", :jpg] }</code></pre>
<p><code>:styles</code> is a hash of thumbnail styles. The styles use the standard ImageMagick geometry rules. Paperclip also adds the &#8216;#&#8217; option which will create square thumbnails that are nicely cropped.</p>
<pre><code class="ruby">has_attached_file :photo, :default_style =&gt; :thumb</code></pre>
<p><code>:default_style</code> is pretty straight forward. You can select a default style from your style list that will be called, instead of the original file, when you use <code>@user.photo.url</code></p>
<pre><code class="ruby">has_attached_file :photo, :path =&gt; ":rails_root/public/:class/:attachment/:id/:style_</code>:basename.:extension<code class="ruby">"</code></pre>
<p>Using <code>:path</code> you can select where the files are saved to on your box. If you change this, make sure to change the <code>:url</code> setting to relate to the new path.</p>
<pre><code class="ruby">has_attached_file :photo, :whiny_thumbnails =&gt; true</code></pre>
<p><code>:whiny_thumbnails</code> will raise an error if there is a problem creating thumbnails. Set to true by default.</p>
<h4>Some Waffle</h4>
<p>Paperclip is a great plugin. It has a smaller memory footprint than Attachment_fu, it doesn&#8217;t require the use of Rmagick (eugh) and it has all the options that I&#8217;ve wished that Attachment_fu had. Give it a try and let me know what you think</p>
<p>Again, maximum kudos to Jon Yurek and all the guys over at <a href="http://www.thoughtbot.com">ThoughtBot</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
