<?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/"
	>

<channel>
	<title>Waggle Labs &#187; Development</title>
	<atom:link href="http://wagglelabs.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://wagglelabs.com</link>
	<description>Social Media, Innovation, Community</description>
	<pubDate>Wed, 26 May 2010 21:03:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Disable deploying to your database server in Capistrano</title>
		<link>http://wagglelabs.com/2008/09/disable-deploying-to-your-database-server-in-capistrano-2/</link>
		<comments>http://wagglelabs.com/2008/09/disable-deploying-to-your-database-server-in-capistrano-2/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 05:09:57 +0000</pubDate>
		<dc:creator>shelly</dc:creator>
		
		<category><![CDATA[All]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[capistrano]]></category>

		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://wagglelabs.wallyhood.org/?p=122</guid>
		<description><![CDATA[
Update: I found a better way, see below
I use Capistrano to not only manage deployment tasks, but also to do lots of data management and monitoring tasks. By default Capistrano will try to deploy your code to whatever server you have set to the :db role, and will try to run the migrations there too. I don’t want to hassle with getting our full rails environment working on the db server so this was always a hassle.
A temporary solution was to just set the :db role to the same server as the :app role and the migrations would get run [...]]]></description>
			<content:encoded><![CDATA[<div class="entry-content">
<p><strong>Update: I found a better way, see below</strong></p>
<p>I use Capistrano to not only manage deployment tasks, but also to do lots of data management and monitoring tasks. By default Capistrano will try to deploy your code to whatever server you have set to the :db role, and will try to run the migrations there too. I don’t want to hassle with getting our full rails environment working on the db server so this was always a hassle.</p>
<p>A temporary solution was to just set the :db role to the same server as the :app role and the migrations would get run on the app server and all would be well. Later though if I had tasks that needed to actually work on the db server I’d have to manually change the :db role value. Very annoying.</p>
<p>To avoid this you have to do two things. First, on your :db role, add the :no_release option like so:</p>
<pre>role :db,  "db.server.com", :primary =&gt; true, :no_release =&gt; true</pre>
<p>This will ensure you don’t have your codes updated to the db server. Next you need to overwrite the default migrate task to not use the :db role. To do this just get the task code from your deploy.rb file. On my system this was in:</p>
<pre>/Library/Ruby/Gems/1.8/gems/capistrano-2.4.3/lib/capistrano/recipes/deploy.rb</pre>
<p>(I admit this is annoying because when you upgrade capistrano you may have to repeat this but I wasn’t able to figure another way.) Grab the migrate task and simply change the role it uses. It should end up looking like this:</p>
<pre> task :migrate, :roles =&gt; :app, :only =&gt; { :primary =&gt; true } do
    rake = fetch(:rake, "rake")
    rails_env = fetch(:rails_env, "production")
    migrate_env = fetch(:migrate_env, "")
    migrate_target = fetch(:migrate_target, :latest)

    directory = case migrate_target.to_sym
      when :current then current_path
      when :latest  then current_release
      else raise ArgumentError, "unknown migration target #{migrate_target.inspect}"
      end

    run "cd #{directory}; #{rake} RAILS_ENV=#{rails_env} #{migrate_env} db:migrate"
  end</pre>
<p>Note that the role was changed to :app (from :db). And you’re done!</p>
<h1>But wait! There is a better way!</h1>
<p>Jamis Buck over in #capistrano eventually replied to a question I had there and explained that there is a much simpler solution:</p>
<pre>[10:34am] jamisbuck: flippyhead: just set one of your app servers to :db, :primary =&gt; true
[10:35am] filmprog: so you've go and added new tasks to deploy:migrate ?
[10:35am] jamisbuck: and then put your db server in the :db role, with :no_release =&gt; false
[10:35am] jamisbuck: and without :primary =&gt; true
[10:35am] jamisbuck: then you'll have your db role
[10:35am] jamisbuck: but your migrations will run on the app server in question
[10:35am] flippyhead: I can refer to role :db twice?
[10:36am] jamisbuck: flippyhead: totally. there's no reason not to
[10:36am] flippyhead: ah, no kiddin!
[10:36am] jamisbuck: the migrations only run on :db where :primary =&gt; true
[10:36am] jamisbuck: any other :db server is ignored
[10:36am] jamisbuck: (by the migration task)</pre>
<p>See, as it turns out you can “overload” roles. So instead of all that I just use this now:</p>
<pre>role :db,  "server.com", :primary =&gt; true
role :db,  "db.server.com", :no_release =&gt; true</pre>
<p>And everything works!</p>
<p>Just remember on those db only tasks to include :only =&gt; {:primary =&gt; false} to refer to the actual db role not the app db role.</p></div>
]]></content:encoded>
			<wfw:commentRss>http://wagglelabs.com/2008/09/disable-deploying-to-your-database-server-in-capistrano-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Complex forms, mass assignment, and the &#8220;presenter&#8221;</title>
		<link>http://wagglelabs.com/2008/09/complex-forms-mass-assignment-and-the-presenter/</link>
		<comments>http://wagglelabs.com/2008/09/complex-forms-mass-assignment-and-the-presenter/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 05:14:16 +0000</pubDate>
		<dc:creator>peter</dc:creator>
		
		<category><![CDATA[All]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://wagglelabs.wallyhood.org/?p=124</guid>
		<description><![CDATA[
I’m fed up with doing a bunch of complex model aggregation in my controllers. They are too bloated. Here’s a set of links I’m trying to make sense of as I decide what to do:

http://validatable.rubyforge.org/
http://pastie.textmate.org/pastes/134685
http://blog.jayfields.com/2007/02/ruby-forwardable-addition.html
http://www.brynary.com/2007/4/8/fluent-interface-for-ruby-delegation
http://weblog.jamisbuck.org/2007/1/11/moving-associated-creations-to-the-model
http://groups.google.com/group/rubyonrails-core/browse_thread/thread/3c61e00916c365e5?pli=1
http://ryandaigle.com/articles/2008/7/19/what-s-new-in-edge-rails-nested-models

Seems like if you can avoid building an extra Presenter model and keep everything in your Rails models you’re better off, though the situation if complex enough, may dictate breaking such stuff out.
Handy in either scenario is Jay Fields validatable plugin for giving you better control over validations on collections of model objects.
The mass assignment stuff that was in edge but has been removed (dammit) may [...]]]></description>
			<content:encoded><![CDATA[<div class="entry-content">
<p>I’m fed up with doing a bunch of complex model aggregation in my controllers. They are too bloated. Here’s a set of links I’m trying to make sense of as I decide what to do:</p>
<ul>
<li><a href="http://validatable.rubyforge.org/">http://validatable.rubyforge.org/</a></li>
<li><a href="http://pastie.textmate.org/pastes/134685">http://pastie.textmate.org/pastes/134685</a></li>
<li><a href="http://blog.jayfields.com/2007/02/ruby-forwardable-addition.html">http://blog.jayfields.com/2007/02/ruby-forwardable-addition.html</a></li>
<li><a href="http://www.brynary.com/2007/4/8/fluent-interface-for-ruby-delegation">http://www.brynary.com/2007/4/8/fluent-interface-for-ruby-delegation</a></li>
<li><a href="http://weblog.jamisbuck.org/2007/1/11/moving-associated-creations-to-the-model">http://weblog.jamisbuck.org/2007/1/11/moving-associated-creations-to-the-model</a></li>
<li><a href="http://groups.google.com/group/rubyonrails-core/browse_thread/thread/3c61e00916c365e5?pli=1">http://groups.google.com/group/rubyonrails-core/browse_thread/thread/3c61e00916c365e5?pli=1</a></li>
<li><a href="http://ryandaigle.com/articles/2008/7/19/what-s-new-in-edge-rails-nested-models">http://ryandaigle.com/articles/2008/7/19/what-s-new-in-edge-rails-nested-models</a></li>
</ul>
<p>Seems like if you can avoid building an extra Presenter model and keep everything in your Rails models you’re better off, though the situation if complex enough, may dictate breaking such stuff out.</p>
<p>Handy in either scenario is <a href="http://jayfields.blogspot.com/">Jay Fields</a> validatable plugin for giving you better control over validations on collections of model objects.</p>
<p>The mass assignment stuff that <strong>was</strong> in edge but has been removed (dammit) may well have been perfect for my needs. As long as my form builders can produce posted parameters as nested hashes that match the model hierarchy I wouldn’t have to do anything by ParentModel.create(params[:parent_model]) and everything is taken care of for me.</div>
]]></content:encoded>
			<wfw:commentRss>http://wagglelabs.com/2008/09/complex-forms-mass-assignment-and-the-presenter/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
