<?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>Sean&#039;s Blog</title>
	<atom:link href="http://seanbehan.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Tue, 31 Aug 2010 14:38:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Collection Select Helper and OnChange Event in Rails</title>
		<link>http://seanbehan.com/posts/collection-select-helper-and-onchange-event-in-rails/</link>
		<comments>http://seanbehan.com/posts/collection-select-helper-and-onchange-event-in-rails/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 14:38:23 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[collection]]></category>
		<category><![CDATA[helpers]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[select]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1162</guid>
		<description><![CDATA[Given a collection of Active Record objects, you may use the collection_select helper method to produce a select form field. You need to pass in a number of arguments to the helper function. 1) object &#8211; your model object used in the collection 2) method &#8211; a valid model attribute or method 3) collection &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>Given a collection of Active Record objects, you may use the collection_select helper method to produce a select form field. You need to pass in a number of arguments to the helper function.</p>
<p>1) object &#8211; your model object used in the collection<br />
2) method &#8211; a valid model attribute or method<br />
3) collection &#8211; a collection of active record model objects<br />
4) option_value &#8211; value being set from the model for the &lt;option value=&#8221;option_value&#8221;&gt; html element<br />
5) option_name &#8211; what is displayed for the user e.g., &lt;option&gt; option_name &lt;<br />
6) option &#8211; general options<br />
7) options for the select html element</p>
<pre># helper and arguments...
# collection_select( model, id, collection, option_value, option_name, options, html_options)

&lt;%= collection_select("states", "state_id",
  State.participating,
  "abbreviation", "name",
   {:selected=&gt; get_current_state_or_nil },
   {:onchange=&gt;"document.location='/states/'+this.value"}
) %&gt;

#which will produce something like...
<pre id="line27">&lt;select id="state_id" name="state[id]" onchange="document.location='/states/'+this.value"&gt;
&lt;option value="AL"&gt;Alabama&lt;/option&gt;
&lt;option value="AK"&gt;Alaska&lt;/option&gt;
&lt;option value="AZ"&gt;Arizona&lt;/option&gt;
&lt;option value="AR"&gt;Arkansas&lt;/option&gt;
&lt;/select&gt;</pre>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/posts/collection-select-helper-and-onchange-event-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Repost</title>
		<link>http://seanbehan.com/ruby/repost/</link>
		<comments>http://seanbehan.com/ruby/repost/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 20:44:05 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[data migrations]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[reset]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1157</guid>
		<description><![CDATA[This post is inspired by http://pupeno.com/blog/really-resetting-the-database/#comment-1179. But as my blog mostly serves as a reference for my future self, I&#8217;d like to reprint this little snippet of code here as well. namespace :db do desc "Crush and burn the database" task :hard_reset => :environment do File.delete("db/schema.rb") Rake::Task["db:drop"].execute Rake::Task["db:create"].execute Rake::Task["db:migrate"].execute Rake::Task["db:seed"].execute if !Rails.env.test? Rake::Task["db:data"].execute end end [...]]]></description>
			<content:encoded><![CDATA[<p>This post is inspired by <a href="http://pupeno.com/blog/really-resetting-the-database/"><br />
http://pupeno.com/blog/really-resetting-the-database/#comment-1179</a>. But as my blog mostly serves as a reference for my future self, I&#8217;d like to reprint this little snippet of code here as well. </p>
<pre>
namespace :db do
  desc "Crush and burn the database"
  task :hard_reset => :environment do
    File.delete("db/schema.rb")
    Rake::Task["db:drop"].execute
    Rake::Task["db:create"].execute
    Rake::Task["db:migrate"].execute
    Rake::Task["db:seed"].execute
    if !Rails.env.test?
      Rake::Task["db:data"].execute
    end
  end

  desc "Generate sample data for developing"
  task :data => :environment do
    # Create the sample data in here
  end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby/repost/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rounded Corners with CSS</title>
		<link>http://seanbehan.com/posts/rounded-corners-with-css/</link>
		<comments>http://seanbehan.com/posts/rounded-corners-with-css/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 00:39:03 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[cross browser]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[rounded corners]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1155</guid>
		<description><![CDATA[.rounded_corners { -moz-border-radius: 20px; -webkit-border-radius: 20px; -khtml-border-radius: 20px; border-radius: 20px; }]]></description>
			<content:encoded><![CDATA[<pre>
.rounded_corners {
     -moz-border-radius: 20px;
    -webkit-border-radius: 20px;
    -khtml-border-radius: 20px;
    border-radius: 20px;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/posts/rounded-corners-with-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Select Distinct in Rails with Active Record</title>
		<link>http://seanbehan.com/ruby-on-rails/select-distinct-in-rails-with-active-record/</link>
		<comments>http://seanbehan.com/ruby-on-rails/select-distinct-in-rails-with-active-record/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 23:23:29 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[active record]]></category>
		<category><![CDATA[distinct]]></category>
		<category><![CDATA[select]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1153</guid>
		<description><![CDATA[User.find :all, :select => "DISTINCT occupation"]]></description>
			<content:encoded><![CDATA[<pre>
User.find :all, :select => "DISTINCT occupation"
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/select-distinct-in-rails-with-active-record/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A List of Every High School in the United States in Pipe Delimitted Form (2005)</title>
		<link>http://seanbehan.com/posts/a-list-of-every-high-school-in-the-united-states-in-pipe-delimitted-form-2005/</link>
		<comments>http://seanbehan.com/posts/a-list-of-every-high-school-in-the-united-states-in-pipe-delimitted-form-2005/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 15:39:00 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[data set]]></category>
		<category><![CDATA[high schools]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1150</guid>
		<description><![CDATA[Here is a text file containing every high school in the United States(2005), including city, state, zip code and high school name. us_high_schools_pd]]></description>
			<content:encoded><![CDATA[<p>Here is a text file containing every high school in the United States(2005), including city, state, zip code and high school name. </p>
<p><a href='http://seanbehan.com/wp-content/uploads/2010/08/us_high_schools_pd.txt'>us_high_schools_pd</a></p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/posts/a-list-of-every-high-school-in-the-united-states-in-pipe-delimitted-form-2005/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Context of Markup vs Expressions of Equality in Determining the Meaning of Angled Brackets</title>
		<link>http://seanbehan.com/posts/the-context-of-markup-vs-expressions-of-equality-in-determining-the-meaning-of-angled-brackets/</link>
		<comments>http://seanbehan.com/posts/the-context-of-markup-vs-expressions-of-equality-in-determining-the-meaning-of-angled-brackets/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 01:18:11 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[angled brackets]]></category>
		<category><![CDATA[context]]></category>
		<category><![CDATA[equality expressions]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1147</guid>
		<description><![CDATA[In the WordPress editor (html mode) you&#8217;ll need to become friends with &#60; and &#62; if you plan on showing any code (php, html&#8230; xml, most languages actually) that readers will want to understand. I never thought about it, but assumed that the lt and gt stood for left, and gt, well, i couldn&#8217;t quite [...]]]></description>
			<content:encoded><![CDATA[<p>In the WordPress editor (html mode) you&#8217;ll need to become friends with &lt; and &gt; if you plan on showing any code (php, html&#8230; xml, most languages actually) that readers  will want to understand. </p>
<p>I never thought about it, but assumed that the lt and gt stood for left, and gt, well, i couldn&#8217;t quite place it, respectively. But alas, it dawned on me. Lt = less than while gt = greater than. Seems obvious now, but when you are thinking about angled brackets as markup, rather than as logic in an expression, the meaning that has value happens to be left vs. right. </p>
<p>Context is important. </p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/posts/the-context-of-markup-vs-expressions-of-equality-in-determining-the-meaning-of-angled-brackets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple Activity Stream Implementation in Rails</title>
		<link>http://seanbehan.com/ruby-on-rails/simple-activity-stream-implementation-in-rails/</link>
		<comments>http://seanbehan.com/ruby-on-rails/simple-activity-stream-implementation-in-rails/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 01:00:21 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[activtiy stream]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[newsfeed]]></category>
		<category><![CDATA[polymorphic associations]]></category>
		<category><![CDATA[simple]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1138</guid>
		<description><![CDATA[There are many ways to tackle the Facebook style activity stream feature for your app. The simplest approach, which you can tack on at almost any moment, is what I&#8217;ll describe here. You don&#8217;t have to create a new model for news feed items or create any polymorphic associations. You simply query for the records [...]]]></description>
			<content:encoded><![CDATA[<p>There are many ways to tackle the Facebook style activity stream feature for your app. The simplest approach, which you can tack on at almost any moment, is what I&#8217;ll describe here. You don&#8217;t have to create a new model for news feed items or create any polymorphic associations. You simply query for the records on separate models you would like aggregated in the stream, and render a partial for that record, which Rails will map for you. </p>
<pre>
# in app/controllers/home_controller.rb
def index
 @activity_stream = (Forum.find(:all, :limit =&gt; 10, :conditions=&gt;["created_at &gt; ?", 1.day.ago]) + ForumPost.find(:all, :limit =&gt; 10)).sort_by {|item| - item.created_at.to_i}
end
</pre>
<p>The sort_by method at the end places all of your feed item into descending chronological order. Omit the minus sign and they will be sorted in ascending order.</p>
<pre>
sort_by {|item| - item.created_at.to_i} # in descending chronological order
</pre>
<p>Show your latest activity in your views&#8230;</p>
<pre>
#app/views/home/index.html.erb
&lt;%= render @activity_stream rescue nil %&gt;
</pre>
<p>This assumes that you will have created the partials for each resource using Rails conventions i.e., you have in created the partials for the models like so app/views/_[the model name].html.erb. In this instance, you should have app/views/forums/_forum.html.erb and app/views/forum_posts/_forum_post.html.erb </p>
<p>You can rename the partials to something like _stream_forum.html.erb, if you already have the forum partial gainfully employed. You&#8217;ll need to change the view and prob. throw it into a loop to either check for a condition or use _stream_[model name].html.erb as the convention for any stream items. </p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/simple-activity-stream-implementation-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scope Routes/URLs By Username (like Twitter) in Your Rails Application</title>
		<link>http://seanbehan.com/posts/scope-routesurls-by-username-like-twitter-in-your-rails-application/</link>
		<comments>http://seanbehan.com/posts/scope-routesurls-by-username-like-twitter-in-your-rails-application/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 21:09:22 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[link_to]]></category>
		<category><![CDATA[routes]]></category>
		<category><![CDATA[scoping]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[urls]]></category>
		<category><![CDATA[usernames]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1135</guid>
		<description><![CDATA[There are a few things that need to be taken care of before you can get this to work. The first thing (although, any of the following steps can be done in any order) to take care of involves your User model. You need to override the to_param method, so that Rails will appropriately use [...]]]></description>
			<content:encoded><![CDATA[<p>There are a few things that need to be taken care of before you can get this to work. The first thing (although, any of the following steps can be done in any order) to take care of involves your User model. You need to override the to_param method, so that Rails will appropriately use the username attribute rather than user_id when constructing paths. </p>
<pre>
#in app/models/user.rb
def to_param
  "#{self.username}"
end
</pre>
<p>Next we move onto routing our resources. Here it gets a little tricky because Rails is building paths for us. Remeber, you can get a list of all currently defined routes in your application by running the routes rake task</p>
<pre>
rake routes
</pre>
<p>We need to set the path_prefix option on any of our resources we want scoped by the username. For instance, in this example, I have set up a Status model and statuses_controller, whose urls shall be scoped by the username. You can apply the path_prefix to any number of other resources in your routes config file. They symbol used is arbitrary, but will be made available in the params hash,  in this case params[:user_id]. You also need to exclude the show action on your users resources declaration. The reason is that, otherwise, Rails will include the controller name in the path like /users/username, which doesn&#8217;t look as clean as just /username. You then need to redefine this route explicitly (last line in the routes config shown here). </p>
<pre>
#in app/config/routes.rb
map.resources :statuses,   :path_prefix =&gt; '/:user_id'
map.resources :users,     :except =&gt; [:show]
map.user '/:username' :controller =&gt; 'users', :action =&gt; 'show'
</pre>
<p>Finally, you get to call these routes in your views or use them in your controllers. You use the same link_to, url_for methods to generate paths. When constructing the resources you have setup with the path_prefix declartion, remember you need the user model as the first argument, followed by said resource. </p>
<pre>
&lt;%= link_to(status.title, status_path(status.user,status) %&gt;
# or in a controller
redirect_to status_path( status.user, status )
</pre>
<p>That&#8217;s pretty much it. If anyone has another way of doing this let me know! </p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/posts/scope-routesurls-by-username-like-twitter-in-your-rails-application/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using Formtastic to Cleanly Create Nice Looking Forms in Rails</title>
		<link>http://seanbehan.com/ruby-on-rails/using-formtastic-to-cleanly-create-nice-looking-forms-in-rails/</link>
		<comments>http://seanbehan.com/ruby-on-rails/using-formtastic-to-cleanly-create-nice-looking-forms-in-rails/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 16:34:13 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[formtastic]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1131</guid>
		<description><![CDATA[Forms can easily get cluttered when you&#8217;re dealing with a lot of form fields&#8230; er, ERB tags. I&#8217;ve written about extending Rails form builders, which certainly goes along way to shrinking your views where forms are used. The plugin Formtastic is even better, as it lets you skirt maintaining your own library in favor of [...]]]></description>
			<content:encoded><![CDATA[<p>Forms can easily get cluttered when you&#8217;re dealing with a lot of form fields&#8230; er, ERB tags. I&#8217;ve written about <a href="http://seanbehan.com/ruby-on-rails/extending-rails-form-builders/">extending Rails form builders</a>, which certainly goes along way to shrinking your views where forms are used. The plugin <a href="http://github.com/justinfrench/formtastic">Formtastic</a> is even better, as it lets you skirt maintaining your own library in favor of a very, elegant DSL.</p>
<p>For a great overview of the plugin and implementation details, check out <a href="http://railscasts.com/episodes/184-formtastic-part-1">Ryan Bate&#8217;s Railscast</a>. There are a couple episodes, but be sure to catch the first one, linked above.</p>
<p>I usually install the plugin as a gem</p>
<pre># config/environment.rb
#...
config.gem "formtastic"
</pre>
<p>and then run a generator to create the stylesheets for me, making forms look nice and neat.</p>
<pre>./script/generate formtastic
</pre>
<p>One gotcha, is that in order for the css to render correctly you need to add this</p>
<pre>&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
</pre>
<p>in the head of your layout file.</p>
<p>You define forms using  &#8220;semantic_form_for&#8221; like so&#8230;</p>
<pre>&lt;% semantic_form_for @user do |f| %&gt;
  &lt;% f.inputs do %&gt;
    &lt;%= f.input :login, :label =&gt; "Username", :hint =&gt; "Something short because it's in the url"%&gt;
  &lt;% end %&gt;
  &lt;%= f.buttons %&gt;
&lt;% end %&gt;
</pre>
<p>As per usual, there are a myriad of configuration options which can be overridden if necessary. Consult the documentation at <a href="http://github.com/justinfrench/formtastic">Justin French&#8217;s Github account</a> for specifics.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/using-formtastic-to-cleanly-create-nice-looking-forms-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TODO and Custom Annotations in Rails Applications</title>
		<link>http://seanbehan.com/ruby-on-rails/todo-and-custom-annotations-in-rails-applications/</link>
		<comments>http://seanbehan.com/ruby-on-rails/todo-and-custom-annotations-in-rails-applications/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 14:59:14 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[annotations]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[tasks]]></category>
		<category><![CDATA[todo]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1128</guid>
		<description><![CDATA[While writing software it&#8217;s common to leave comments for your future self. For instance, if you have written some code but realize that it should be refactored to be more efficient, you may place something along the lines of &#8220;TODO: change active record find method and replace w/ a custom sql select finder &#8220;. With [...]]]></description>
			<content:encoded><![CDATA[<p>While writing software it&#8217;s common to leave comments for your future self. For instance, if you have written some code but realize that it should be refactored to be more efficient, you may place something along the lines of &#8220;TODO: change active record find method and replace w/ a custom sql select finder &#8220;. With rails, if you follow this convention, you can get a list of your annotations with a rake task.</p>
<pre>
rake notes:todo
</pre>
<p>which will print out the file where the the todo was found along with the line number and the comment&#8230; </p>
<pre>
app/controllers/application_controller.rb:
  * [  8] fix me
</pre>
<p>Rails defines several other annotation types for you</p>
<pre>
rake notes                                # Enumerate all annotations
rake notes:fixme                          # Enumerate all FIXME annotations
rake notes:optimize                       # Enumerate all OPTIMIZE annotations
rake notes:todo                           # Enumerate all TODO annotations
</pre>
<p>And you also may define your own</p>
<pre>
# SEAN: please rewrite this method to query only chunky bacon
</pre>
<p>you may find all instances of &#8220;SEAN&#8221; by running</p>
<pre>
rake notes:custom ANNOTATION=SEAN
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/todo-and-custom-annotations-in-rails-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
