<?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>Cameron Stitt</title>
	<atom:link href="http://blog.castitt.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.castitt.com</link>
	<description>Just another Web Developer blog</description>
	<lastBuildDate>Fri, 09 Dec 2011 00:20:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>LINQ to SQL</title>
		<link>http://blog.castitt.com/2011/09/linq-to-sql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linq-to-sql</link>
		<comments>http://blog.castitt.com/2011/09/linq-to-sql/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 00:03:23 +0000</pubDate>
		<dc:creator>Cameron</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[linqtosql]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://blog.castitt.com/?p=70</guid>
		<description><![CDATA[As a programmer that loves frameworks like Ruby on Rails, one frustration I always had with .Net was the lack of frameworks that were easy to use and just worked. When I started work at my current employer&#8217;s in January, they had a framework that had previously been developed that they were using. I went [...]]]></description>
			<content:encoded><![CDATA[<p>As a programmer that loves frameworks like Ruby on Rails, one frustration I always had with .Net was the lack of frameworks that were easy to use and just worked. When I started work at my current employer&#8217;s in January, they had a framework that had previously been developed that they were using. I went on using it and making modifications to it so that it would continue to meet our needs and complete simple tasks.</p>
<p><span id="more-70"></span></p>
<p>A few weeks ago, I friend of mine showed me LINQ to SQL and after 30 seconds of reading up on it I was hooked. Why hadn&#8217;t I seen this before? It has been in the .Net framework for some time as far as I can see. I suppose it was another one of those cases where you don&#8217;t notice it until you need it. That is one issue I do have with .Net, it has so many features and yet you may never even know half of the things that it is capable of. That&#8217;s a conversation for another day though. LINQ to SQL allows you to easily create objects that you can interact with which also includes features such as:</p>
<ul>
<li>Parent/Child entities</li>
<li>Stored Procedure calling as methods</li>
<li>Customisation and the ability to override all of the methods and classes</li>
<li>and much more</li>
</ul>
<p>To find out more on LINQ to SQL, I recommend reading the following series from Scott Gu&#8217;s blog.</p>
<p><a href="http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx">Using LINQ to SQL (Part 1)</a></p>
<p>Until next time!</p>
<p>Cameron</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.castitt.com/2011/09/linq-to-sql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Blog Updates: New Theme, New Pages</title>
		<link>http://blog.castitt.com/2011/07/blog-updates-new-theme-new-pages/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=blog-updates-new-theme-new-pages</link>
		<comments>http://blog.castitt.com/2011/07/blog-updates-new-theme-new-pages/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 06:14:45 +0000</pubDate>
		<dc:creator>Cameron</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.castitt.com/?p=66</guid>
		<description><![CDATA[Hi there faithful readers. How is everyone going? Well I hope. Just wanted to let you know that I have updated a few different parts of the blog as I finally have some time to spend on producing new content. Firstly, I have updated the Theme to use the Showcase theme by MidPhase. It&#8217;s a [...]]]></description>
			<content:encoded><![CDATA[<p>Hi there faithful readers. How is everyone going? Well I hope. Just wanted to let you know that I have updated a few different parts of the blog as I finally have some time to spend on producing new content. Firstly, I have updated the Theme to use the Showcase theme by MidPhase. It&#8217;s a modern, but elegant theme and I love it.</p>
<p>Secondly, I have created a few new pages. I have created a Project page that contains information on the different types of projects that I am a part of. This includes open source projects as well as websites that I have completed for clients. The second page I have created is a contact form. Please feel free to go there and shoot me an email with any ideas for a blog post or even any ideas you have to make the blog work better.</p>
<p>Thanks,</p>
<p>Cameron</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.castitt.com/2011/07/blog-updates-new-theme-new-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Site &#8211; McMaster Refrigeration</title>
		<link>http://blog.castitt.com/2011/05/new-site-mcmaster-refrigeration/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=new-site-mcmaster-refrigeration</link>
		<comments>http://blog.castitt.com/2011/05/new-site-mcmaster-refrigeration/#comments</comments>
		<pubDate>Tue, 31 May 2011 00:56:56 +0000</pubDate>
		<dc:creator>Cameron</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.castitt.com/?p=47</guid>
		<description><![CDATA[Hi, Here are a few screenshots from a new site I have recently completed. A link to the site is at the bottom of the post. McMaster Refrigeration Site Thanks, Cameron]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>Here are a few screenshots from a new site I have recently completed. A link to the site is at the bottom of the post.<span id="more-47"></span></p>
<p><a href="http://blog.castitt.com/wp-content/uploads/2011/05/mac1.jpg"><img class="size-medium wp-image-49 aligncenter" title="McMaster Refrigeration - Home" src="http://blog.castitt.com/wp-content/uploads/2011/05/mac1-300x256.jpg" alt="McMaster Refrigeration - Home" width="300" height="256" /></a></p>
<p><a href="http://blog.castitt.com/wp-content/uploads/2011/05/mac1.jpg"></a><a href="http://blog.castitt.com/wp-content/uploads/2011/05/mac2.jpg"><img class="aligncenter size-medium wp-image-50" title="McMaster Refrigeration - History" src="http://blog.castitt.com/wp-content/uploads/2011/05/mac2-300x256.jpg" alt="McMaster Refrigeration - History" width="300" height="256" /></a></p>
<p><a href="http://blog.castitt.com/wp-content/uploads/2011/05/mac3.jpg"><img class="aligncenter size-medium wp-image-51" title="McMaster Refrigeration - Projects" src="http://blog.castitt.com/wp-content/uploads/2011/05/mac3-300x256.jpg" alt="McMaster Refrigeration - Projects" width="300" height="256" /></a></p>
<p><a href="http://www.mcmaster-refrigeration.com.au">McMaster Refrigeration Site</a></p>
<p>Thanks,</p>
<p>Cameron</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.castitt.com/2011/05/new-site-mcmaster-refrigeration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Idea &#8211; Web Conference at Rockhampton</title>
		<link>http://blog.castitt.com/2011/04/my-idea-web-conference-at-rockhampton/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=my-idea-web-conference-at-rockhampton</link>
		<comments>http://blog.castitt.com/2011/04/my-idea-web-conference-at-rockhampton/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 11:21:22 +0000</pubDate>
		<dc:creator>Cameron</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.castitt.com/?p=45</guid>
		<description><![CDATA[Today I posted on Twitter that I had an idea that would benefit the Rockhampton Information Technology crowd. If you haven&#8217;t caught onto the idea after reading the title of this post, here is the grand revelation! A Web Conference to be held in Rockhampton for user&#8217;s or managers of Web technologies within the Central [...]]]></description>
			<content:encoded><![CDATA[<p>Today I posted on Twitter that I had an idea that would benefit the Rockhampton Information Technology crowd. If you haven&#8217;t caught onto the idea after reading the title of this post, here is the grand revelation! A Web Conference to be held in Rockhampton for user&#8217;s or managers of Web technologies within the Central Queensland region. I am truly excited by this concept and believe that it can work for a number of reasons:<span id="more-45"></span></p>
<ol>
<li>Rockhampton has a reasonably large (larger than many would think) Web industry</li>
<li>As Rockhampton is a regional town, many members of the Web crowd would have never been to one of the larger nationally or internationally run conferences</li>
<li>It would also give an opportunity for people to meet companies within CQ. Especially for students within the region.</li>
<li>Networking is something that can be hard to achieve when working with the Web. We are generally isolated people that tend to work within our teams and no further. This would give attendee&#8217;s an opportunity to mingle with the other bright minds within the region and share their knowledge and experience with each other.</li>
</ol>
<p>Examples of topics I would expect the conference to cover are as follows:</p>
<ul>
<li>Management concepts for web based teams / projects</li>
<li>Tips, tricks and concepts in regards to languages used for the web (eg. HTML5, CSS3 etc)</li>
<li>Discussions on how to successfully manage a Web Server</li>
</ul>
<p>I will be releasing more information about the concept and such at a later date as this is still very early stages. If you have any thoughts on the subject please comment below, send me an email or send me a message via twitter (@camstitt).</p>
<p>Thanks,</p>
<p>Cameron</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.castitt.com/2011/04/my-idea-web-conference-at-rockhampton/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Site &#8211; Convergenius</title>
		<link>http://blog.castitt.com/2011/04/new-site-convergenius/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=new-site-convergenius</link>
		<comments>http://blog.castitt.com/2011/04/new-site-convergenius/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 00:21:43 +0000</pubDate>
		<dc:creator>Cameron</dc:creator>
				<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://blog.castitt.com/?p=42</guid>
		<description><![CDATA[I have recently completed a number projects and will now be posting details of these project here on my blog. Firstly, a little bit about Convergenius. The following is extracted from their site: Convergenius works with leading enterprises in tackling their most difficult and unique organisational challenges. These challenges often relate to the lack of [...]]]></description>
			<content:encoded><![CDATA[<p>I have recently completed a number projects and will now be posting details of these project here on my blog.</p>
<p>Firstly, a little bit about Convergenius. The following is extracted from their site:</p>
<blockquote><p>Convergenius works with leading enterprises in tackling their most  difficult and unique organisational challenges. These challenges often  relate to the lack of visibility over key business processes such as  Risk and Hazard management, Work and Competency management, inadequate association of key Work  Pack information through static document management and report writing  capability and lack of visibility over Compliance Management.</p></blockquote>
<p><span id="more-42"></span><br />
The Convergenius project came to me with a design already in place that did not need to be modified to much. The majority of the work that needed to be completed was updating the content. I did however modify the navigation and width of the site to match the new content. Furthermore, I migrated the old design to use more CSS3 and therefore include progressive enhancement.</p>
<p><a href="http://blog.castitt.com/wp-content/uploads/2011/04/conv-home.jpg"><img class="size-medium wp-image-43 aligncenter" title="Convergenius" src="http://blog.castitt.com/wp-content/uploads/2011/04/conv-home-300x231.jpg" alt="" width="300" height="231" /></a>To view the site, follow the link below:</p>
<p><a title="Convergenius" href="http://www.convergenius.com/">http://www.convergenius.com</a></p>
<p>Thanks,</p>
<p>Cameron</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.castitt.com/2011/04/new-site-convergenius/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Where have I been?</title>
		<link>http://blog.castitt.com/2011/04/where-have-i-been/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=where-have-i-been</link>
		<comments>http://blog.castitt.com/2011/04/where-have-i-been/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 23:26:30 +0000</pubDate>
		<dc:creator>Cameron</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.castitt.com/?p=40</guid>
		<description><![CDATA[The past few months have been a truly busy time for me. I have moved town, started a new job, worked on a few client projects, started playing football again as well as many other things. Throughout this time I kept thinking &#8220;I really should blog again&#8221;. Well here I am, blogging again. I have [...]]]></description>
			<content:encoded><![CDATA[<p>The past few months have been a truly busy time for me. I have moved town, started a new job, worked on a few client projects, started playing football again as well as many other things. Throughout this time I kept thinking &#8220;I really should blog again&#8221;. Well here I am, blogging again. I have a few interesting topics I will be covering over the next few weeks and am looking forward to getting back into the flow of blogging.</p>
<p>Thanks,</p>
<p>Cameron</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.castitt.com/2011/04/where-have-i-been/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple File Uploads Using jQuery and Paperclip</title>
		<link>http://blog.castitt.com/2011/02/multiple-file-uploads-using-jquery-and-paperclip/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=multiple-file-uploads-using-jquery-and-paperclip</link>
		<comments>http://blog.castitt.com/2011/02/multiple-file-uploads-using-jquery-and-paperclip/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 04:58:33 +0000</pubDate>
		<dc:creator>Cameron</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Attachments]]></category>
		<category><![CDATA[File Upload]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Paperclip]]></category>
		<category><![CDATA[Rails 3]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.castitt.com/?p=37</guid>
		<description><![CDATA[File uploads is something that is used in Web Applications all of the time. It is becoming somewhat of a &#8220;standard&#8221; feature in many applications. When using rails, there are a number of ways that this feature can be achieved. Originally, I used attachment_fu and followed a tutorial (which I have since lost) that described [...]]]></description>
			<content:encoded><![CDATA[<p>File uploads is something that is used in Web Applications all of the time. It is becoming somewhat of a &#8220;standard&#8221; feature in many applications. When using rails, there are a number of ways that this feature can be achieved. Originally, I used attachment_fu and followed a tutorial (which I have since lost) that described how to perform multi-file uploads. This worked wonders. However, attachment_fu has somewhat fallen behind, or perhaps is no longer even supported. I have since started using <a href="https://github.com/thoughtbot/paperclip" target="_blank">Paperclip</a>, as it seems to be the most common file upload plugin used for Rails and is very well supported.</p>
<p>The second element of this tutorial is jQuery. jQuery is one of the most popular javascript library&#8217;s that is used on the web. Furthermore, it is even easier to use with rails since the upgrade to Rails 3 and the release of the <a href="https://github.com/rails/jquery-ujs" target="_blank">jquery-ujs</a> gem. It only seems natural that someone would want to use Paperclip and jQuery together, and this tutorial shows you how.</p>
<p><span id="more-37"></span></p>
<h3>Requirements</h3>
<ul>
<li>Rails 3</li>
<li>Intermediate knowledge of Ruby on Rails</li>
<li>Intermediate knowledge of jQuery and Javascript</li>
</ul>
<h3>Paperclip</h3>
<p>The setup of Paperclip is almost standard, however we are going to modifying one or two things to allow for multiple file uploading. Firstly, install the gem.</p>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
#gemfile
gem "paperclip"
#console
bundle install
</pre>
<p>We are going to call our Paperclip attachments &#8220;Assets&#8221;. Here is our setup process.</p>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
#generate scaffold
rails g scaffold asset data_file_name:string data_content_type:string data_file_size:integer attachable:references
#create_assets.rb migration
#change
t.references :attachable
#to
t.references :attachable, :polymorphic =&gt; true
#add index after create_table
add_index :assets, [:attachable_id, :attachable_type]
</pre>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
#asset.rb model
class Asset &lt; ActiveRecord::Base
#path is generally set by default, but i had to set mine
has_attached_file :data, :url =&gt; "/assets/:id", :path =&gt; ":rails_root/public/system/assets/:id/:basename.:extension"

belongs_to :attachable, :polymorphic =&gt; true

#Set number to the Max Attachments allowed for owner
Max_Attachments = 5
Max_Attachment_Size = 2.megabyte

def url(*args)
data.url(*args)
end

def name
data_file_name
end

def content_type
data_content_type
end

def file_size
data_file_size
end
end

#in the model that is going to have the attachments added to it.
has_many :assets, :as =&gt; :attachable, :dependent =&gt; :destroy
accepts_nested_attributes_for :assets

validate :validate_attachments
def validate_attachments
errors.add_to_base("Too many attachments - maximum is #{Asset::Max_Attachments}") if assets.length &gt; Asset::Max_Attachments
assets.each {|a| errors.add_to_base("#{a.name} is over #{Asset::Max_Attachment_Size/1.megabyte}MB") if a.file_size &gt; Asset::Max_Attachment_Size}
end
</pre>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
class AssetsController &lt; ApplicationController
def show
asset = Asset.find(params[:id])
#do security check here
send_file asset.data.path, :type =&gt; asset.data_content_type
end

#this will be called via ajax/remote
def destroy
asset = Asset.find(params[:id])
@allowed = Asset::Max_Attachments - asset.attachable.assets.count

@attachable = asset.attachable

if asset.destroy
respond_to do |format|
format.html do
if request.xhr?
#get attachable item again to ensure we get the new asset list
render :partial =&gt; "attachments", :collection =&gt; Attachable.find(@attachable.id).assets
end
end
end
else
respond_to do |format|
format.html do
if request.xhr?
render :json =&gt; asset.errors
end
end
end
end
end
end
</pre>
<p>In the forms:</p>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
#the file field to add a new one. Disabled if there are already the max number of attachments
&lt;div id="attachment_fields"&gt;
&lt;% if @attachable.assets.count &gt;= Asset::Max_Attachments %&gt;
&lt;input id="newfile_data" type="file" disabled /&gt;
&lt;% else %&gt;
&lt;input id="newfile_data" type="file" /&gt;
&lt;% end %&gt;
&lt;/div&gt;
#the list of pending attachments
&lt;p&gt;Pending Attachments: (Max of &lt;%= Asset::Max_Attachments %&gt; each under &lt;%= Asset::Max_Attachment_Size/1.megabyte%&gt;MB)&lt;/p&gt;
&lt;div id="attachment_list"&gt;
&lt;ul id="pending_files"&gt;&lt;/ul&gt;
&lt;/div&gt;
#the list of already attached files (required for edit form only)
&lt;p&gt;Attached Files:&lt;/p&gt;
&lt;div id="attachment_list"&gt;
&lt;%= render :partial =&gt; "attachment", :collection =&gt; @attachable.assets %&gt;
&lt;/div&gt;
</pre>
<p>The attachment partial:</p>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
&lt;% if !attachment.id.nil? %&gt;
&lt;li id="attachment_&lt;%=attachment.id %&gt;"&gt;
&lt;a href="&lt;%=attachment.url %&gt;"&gt;
&lt;%=attachment.name %&gt;
&lt;/a&gt;
(&lt;%=attachment.file_size/1.kilobyte %&gt;KB)
#only needed if in edit action
&lt;% if action_name == "edit" %&gt;
&lt;%= link_to "Remove", asset_path(:id =&gt; attachment), :method =&gt; :delete, :confirm =&gt; "Are you sure you want to delete " + attachment.name + "?", :remote =&gt; true, :class =&gt; 'remove_file' %&gt;
&lt;% end %&gt;
&lt;/li&gt;
&lt;% end %&gt;
</pre>
<p>Okay so that almost it. The last thing we need to add is the javascript to remove a Asset via ajax, handle the file field change event and also remove a non-uploaded file.</p>
<pre class="brush: jscript; title: ; wrap-lines: false; notranslate">
$(document).ready(function(){
//change form button text on submit. Handy for general usage.
$('form').submit(function(){
$('input[name="commit"]', this).attr('value', "Submitting...");
$('input[name="commit"]', this).attr('disabled', 'disabled');
});

//ajax for removing the file from the list of attachments
$('.remove_file')
.live("ajax:beforeSend", function(evt, xhr, settings){
var $form = $('.attachable_form');
var $submitButton = $form.find('input[name="commit"]');

$submitButton.data('origText', $submitButton.attr('value'));
$submitButton.attr('value', "Waiting...");
$submitButton.attr("disabled", true);
})
.live("ajax:success", function(evt, data, status, xhr){
$('#attached_list').html(xhr.responseText);
})
.live("ajax:complete", function(evt, xhr, status){
//always set form class to 'attachable_form' when they have an asset
var $form = $('.attachable_form');
var $submitButton = $form.find('input[name="commit"]');

$submitButton.attr('value', $submitButton.data('origText'));
$submitButton.attr("disabled", false);
})
.live("ajax:error", function(evt, xhr, status, error){
var $form = $('.attachable_form'),
errors,
errorText;

try {
// Populate errorText with the comment errors
errors = $.parseJSON(xhr.responseText);
} catch(err) {
// If the responseText is not valid JSON (like if a 500 exception was thrown), populate errors with a generic error message.
errors = {message: "Please reload the page and try again"};
}

// Build an unordered list from the list of errors
errorText = "There were errors with the submission: \n&lt;ul&gt;";

for ( error in errors ) {
errorText += "&lt;li&gt;" + error + ': ' + errors[error] + "&lt;/li&gt; ";
}

errorText += "&lt;/ul&gt;";

// Insert error list into form
$('div#errorExplanation').html(errorText);
});
$('input:file').live('change', function(){
var index = $('#pending_files').children().size();
var totalAssets = index + $('#attachment_list').children().size() + 1;
if (totalAssets &lt; 5)
{
$('#attachment_fields').prepend("&lt;input type='file' id='newfile_data' /&gt;");
}
else
{
$('#attachment_fields').prepend("&lt;input type='file' id='newfile_data' disabled /&gt;");
}
$(this).css('position', 'absolute');
$(this).css('left', '-1000px');
$(this).attr('name', 'attachment[file_' + index + ']');
var fileText = "&lt;li&gt;" + $(this).val() + " &lt;a href='#' class='remove_pending' title='Remove this attachment'&gt;Remove&lt;/a&gt;&lt;/li&gt;";
$('#pending_files').prepend(fileText);
});
$('.remove_pending').live('click', function(){
var thisIndex = $('#pending_files').index($(this).parent());
var position = thisIndex++;
$('#attachment_fields').children().eq(position).remove();
$(this).parent().remove();
var totalAssets = $('#pending_files').children().size() + $('#attachment_list').children().size();
if (totalAssets &lt; 5)
{
$('#attachment_fields input:first-child').removeAttr('disabled');
}
return false;
});
});
</pre>
<p>To create this, I read a bunch of tutorials on the many different aspects of rails including the following:</p>
<ul>
<li><a href="http://www.cordinc.com/blog/2009/04/multiple-attachments-with-vali.html" target="_blank">Multiple attachments with Validations In Rails with Paperclip</a></li>
<li><a href="http://www.alfajango.com/blog/rails-3-remote-links-and-forms/" target="_blank">Rails 3 Remote Links and Forms: A Definitive Guide</a></li>
</ul>
<p>I hope that this post has helped you out!</p>
<p>Thanks,</p>
<p>Cameron</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.castitt.com/2011/02/multiple-file-uploads-using-jquery-and-paperclip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Authlogic Issues With Rails 3</title>
		<link>http://blog.castitt.com/2010/11/some-gem-issues-with-rails-3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=some-gem-issues-with-rails-3</link>
		<comments>http://blog.castitt.com/2010/11/some-gem-issues-with-rails-3/#comments</comments>
		<pubDate>Mon, 15 Nov 2010 00:46:16 +0000</pubDate>
		<dc:creator>Cameron</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Authlogic]]></category>
		<category><![CDATA[Rails 3]]></category>

		<guid isPermaLink="false">http://blog.castitt.com/?p=34</guid>
		<description><![CDATA[My upgrade to Rails 3 has been surprisingly smooth,  however there have been a few minor issues with one of the Gems I use frequently, Authlogic. Both issues occur in the user_session model. The first issue occurs when trying to load the user_sessions#new action. To fix this issue, we must add the following method to [...]]]></description>
			<content:encoded><![CDATA[<p>My upgrade to Rails 3 has been surprisingly smooth,  however there have been a few minor issues with one of the Gems I use frequently, Authlogic. Both issues occur in the user_session model.<br />
<span id="more-34"></span><br />
The first issue occurs when trying to load the user_sessions#new action.</p>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
NoMethodError in User_sessions#new
undefined method `key' for #&lt;UserSession: no credentials provided&gt;</pre>
<p>To fix this issue, we must add the following method to the user_session model.</p>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
def to_key
  new_record? ? nil : [ self.send(self.class.primary_key) ]
end
</pre>
<p>The second issue occurs at the user_sessions#create action. The URL looks something like /user_sessions/%23&#8230;&#8230; and this obviously throws an error. The solution is to change the form tag in new.html.erb.</p>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
&lt;% form_for (@user_session, :url =&gt; { :action =&gt; &quot;create&quot; }) do |f| %&gt;
#or for formtastic
&lt;% semantic_form_for @user_session, :url =&gt; { :action =&gt; &quot;create&quot; } do |f| %&gt;
</pre>
<p>Hope this helps.</p>
<p>Thanks,</p>
<p>Cameron</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.castitt.com/2010/11/some-gem-issues-with-rails-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Friendly URL&#8217;s with Ruby on Rails</title>
		<link>http://blog.castitt.com/2010/10/friendly-urls-with-ruby-on-rails/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=friendly-urls-with-ruby-on-rails</link>
		<comments>http://blog.castitt.com/2010/10/friendly-urls-with-ruby-on-rails/#comments</comments>
		<pubDate>Sat, 30 Oct 2010 05:44:06 +0000</pubDate>
		<dc:creator>Cameron</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[friendly-id]]></category>
		<category><![CDATA[Gem]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.castitt.com/?p=31</guid>
		<description><![CDATA[Rails is a truly beautiful framework to create powerful applications quickly and easily. However something I have never liked about it are the auto generated URL&#8217;s. I understand that using the Id of the object is not a problem in most cases, however it doesn&#8217;t seem feasible if you are going to end up having [...]]]></description>
			<content:encoded><![CDATA[<p>Rails is a truly beautiful framework to create powerful applications quickly and easily. However something I have never liked about it are the auto generated URL&#8217;s. I understand that using the Id of the object is not a problem in most cases, however it doesn&#8217;t seem feasible if you are going to end up having a large number of rows in a table.<br />
<span id="more-31"></span><br />
A number of posts that I read suggested using a mixture of the object Id and a slug such as (http://domain.com/142-test-object), which is okay for semi-friendly URL&#8217;s. However you still have the issue of the Id being part of the visible URL and the possible length of the Id. The URL we want to achieve should look like the following:</p>
<p>http://domain.com/test-object</p>
<p>To do so, we will be using the friendly-id gem by norman. It is an easy to use gem that does not require much setting up to use.</p>
<h2>Installation</h2>
<p><em>Note: The following is for Rails 3 only.</em></p>
<p>To install, first add the following line to your Gemfile.</p>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
gem &quot;friendly_id&quot;, &quot;~&gt; 3.1&quot;
</pre>
<p>Then run:</p>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
bundle install

rails g friendly_id

rake db:migrate
</pre>
<h2>Usage</h2>
<p>To use friendly-id for a scaffold, you have to ensure you have a column called cached_slug of type string.</p>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
rails g scaffold project name:string cached_slug:string
</pre>
<p>Again ensure that you migrate the database after running the scaffold. Now we enter the following into the model to tell rails to use friendly-id.</p>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
has_friendly_id :name, :use_slug =&gt; true
</pre>
<p>All done, now when a project is created, the name will be used in the URL.</p>
<h2>Additional Options</h2>
<p>The :use_slug condition in the above example is optional. It should be used when the field that will be the URL will not necessarily be unique. Therefore, if you have a model and will be using a unique field, you do not have to have the :use_slug condition. <strong>EDIT:</strong> Turns out this is wrong. Yes it&#8217;s optional, but my description of why is incorrect. Read <a href="http://friendly-id.rubyforge.org/" target="_blank">this</a> for the real usage.</p>
<pre class="brush: ruby; title: ; wrap-lines: false; notranslate">
has_friendly_id :name
</pre>
<p>There are a number of other features which can be found on the github page. The link can be found at the bottom of the post.</p>
<p>I hope this gem is as useful to you as it was to me!</p>
<p>Thanks,</p>
<p>Cameron</p>
<h3>Links</h3>
<p>GitHub page:         <a href="http://github.com/norman/friendly_id">http://github.com/norman/friendly_id</a></p>
<p>Friendly-id API:    <a href="http://friendly-id.rubyforge.org/">http://friendly-id.rubyforge.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.castitt.com/2010/10/friendly-urls-with-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Moving On</title>
		<link>http://blog.castitt.com/2010/10/moving-on/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=moving-on</link>
		<comments>http://blog.castitt.com/2010/10/moving-on/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 00:47:58 +0000</pubDate>
		<dc:creator>Cameron</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://blog.castitt.com/?p=28</guid>
		<description><![CDATA[It has been two months since I last posted and thought it was time to give an update as to where I am at and what I have been doing. A number of months ago, my partner got offered a position to work in Rockhampton, Queensland. We both grew up in Rockhampton and had been [...]]]></description>
			<content:encoded><![CDATA[<p>It has been two months since I last posted and thought it was time to give an update as to where I am at and what I have been doing. A number of months ago, my partner got offered a position to work in Rockhampton, Queensland. We both grew up in Rockhampton and had been discussing if we wanted to move back after a number of years in Brisbane. After much discussion, she accepted the position and begins work early next year (as she still has a month of study till graduation).<span id="more-28"></span></p>
<p>Once the position had been accepted and therefore the decision to move back to Rockhampton had been made, it came time for me to re-evaluate my career and how I was going to handle the re-location. I have spent the last few months searching for available positions in Rockhampton (there are not many around) and also looking for jobs that allow the successful applicant to &#8220;work from home&#8221; (not many of these around either). I have even looked at some more radical ideas for employment, none of which were enticing enough for me to move in that direction.</p>
<p>So here is where I give myself a plug for any employer&#8217;s looking for a skilled Web Developer. I have 3 years experience working with the web and have worked on a number of large scale projects in both large and small team situations. I have experience in a range of areas including but not limited to:</p>
<ul>
<li>C# / .Net</li>
<li>Ruby on Rails (RoR)</li>
<li>HTML4</li>
<li>CSS2 &amp; CSS3</li>
<li>Javascript</li>
<li>JQuery, Prototype, script.aculo.us</li>
<li>Linux based RoR development</li>
<li>Windows based RoR development</li>
<li>Git, GitHub</li>
<li>Deployment of Git/RoR applications</li>
<li>MySQL, SQLite, SQLServer</li>
</ul>
<p>I am not one to talk myself up to often however I believe that I am a highly skilled Web Developer with a motivation to create highly detailed, beautiful looking Web Sites and Applications. If you have any work for me (either contract, part-time or full-time) please contact me via email at <a href="mailto:cameron@castitt.com">cameron@castitt.com</a> or via twitter <a href="http://twitter.com/camstitt" target="_blank">@camstitt</a>.</p>
<p>I will be back to writing tutorials etc soon.</p>
<p>Thanks,</p>
<p>Cameron</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.castitt.com/2010/10/moving-on/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

