<?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>Infectious Learning</title>
	<atom:link href="http://www.logansbailey.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.logansbailey.com</link>
	<description>Adventures in web development</description>
	<lastBuildDate>Sat, 11 Feb 2012 04:08:47 +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>An issue with the full stack framework</title>
		<link>http://www.logansbailey.com/2012/02/10/an-issue-with-the-full-stack-framework/</link>
		<comments>http://www.logansbailey.com/2012/02/10/an-issue-with-the-full-stack-framework/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 19:14:56 +0000</pubDate>
		<dc:creator>Logan Bailey</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.logansbailey.com/?p=463</guid>
		<description><![CDATA[I&#8217;ve tried several times to learn RoR. I can get around Ruby in a haphazard manner. I&#8217;ve even written a few small RoR sites. But there was so much happening behind the scenes, under the hood, that I never felt &#8230;<p class="read-more"><a href="http://www.logansbailey.com/2012/02/10/an-issue-with-the-full-stack-framework/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve tried several times to learn <a href="http://rubyonrails.org">RoR</a>. I can get around Ruby in a haphazard manner. I&#8217;ve even written a few small RoR sites. But there was so much happening behind the scenes, under the hood, that I never felt happy with my knowledge and understanding of what was going on. Today while  listening to <a href="https://twitter.com/#!/funkatron">@funkatron</a>&#8216;s <a href="http://www.engineyard.com/podcast/s02e06-ed-finkler">EngineYard podcast</a>, he mentioned that there was a  ruby/erlang dev on their team. The dev found the code base much easier to parse  and understand after switching from a full stack framework to <a href="http://www.slimframework.com/">Slim Framework</a> .</p>
<p>People often post on user boards &#8211; &#8220;I want to learn php which framework should I use?&#8221;. If you&#8217;re going about learning a language by using a framework written in that  language &#8211; stay away from full stack frameworks. You&#8217;ll have a much enjoyable time using a simpler more &#8220;declarative&#8221; framework.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logansbailey.com/2012/02/10/an-issue-with-the-full-stack-framework/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Issues with alternative captchas</title>
		<link>http://www.logansbailey.com/2012/01/20/issues-with-alternative-captchas/</link>
		<comments>http://www.logansbailey.com/2012/01/20/issues-with-alternative-captchas/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 17:16:56 +0000</pubDate>
		<dc:creator>Logan Bailey</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.logansbailey.com/?p=440</guid>
		<description><![CDATA[Nobody likes captchas, spammers find them annoying and users find them obnoxious. But it&#8217;s an easy way to separate out the spammers from the users. There have long been many alternative solutions to the common captcha, and they all have &#8230;<p class="read-more"><a href="http://www.logansbailey.com/2012/01/20/issues-with-alternative-captchas/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Nobody likes captchas, spammers find them annoying and users find them obnoxious. But it&#8217;s an easy way to separate out the spammers from the users. There have long been many alternative solutions to the common captcha, and they all have their own issues.</p>
<p>One solution is to show the user an easy math problem: <i>2 + three =</i>. While this is easier for the user, a <a title="No robots were fooled in the parsing of this captcha" href="https://www.google.com/search?q=2+%2B+three+%3D" target="_blank">quick Google</a>&nbsp;search will give the spammer the answer.</p>
<p>Today I saw another alternative for captchas in Hasin&#8217;s blog post <a href="http://hasin.me/2012/01/19/time-to-put-those-fucking-captchas-to-an-end/" target="_blank">Time to put those FUCKING captchas to an end</a>. His alternative captcha theory is to show you an easily identified object, a tree or statue, and have you say what it is. Spammer&#8217;s solution: run the image through Google&#8217;s photo search. The third example, where the picture asks &#8220;There are two ___&#8221; and then shows two squares and three triangles, did stump Google. But this image would not be difficult to parse and answer.</p>
<p>The current captcha system is painful, tedious, and can be comical at times, but it does knock off a majority of the spammers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logansbailey.com/2012/01/20/issues-with-alternative-captchas/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Date Formatting and Customizing Devise</title>
		<link>http://www.logansbailey.com/2011/03/07/date-formatting-and-customizing-devise/</link>
		<comments>http://www.logansbailey.com/2011/03/07/date-formatting-and-customizing-devise/#comments</comments>
		<pubDate>Tue, 08 Mar 2011 06:43:38 +0000</pubDate>
		<dc:creator>Logan Bailey</dc:creator>
				<category><![CDATA[Rails Tutorial Blog]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ror]]></category>

		<guid isPermaLink="false">http://www.logansbailey.com/?p=411</guid>
		<description><![CDATA[This week will focus on formatting the rails app to be more user friendly. If this is your first time to this site, please see the first post on making your owns rails blog. Before we start with this weeks &#8230;<p class="read-more"><a href="http://www.logansbailey.com/2011/03/07/date-formatting-and-customizing-devise/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>This week will focus on formatting the rails app to be more user friendly.  If this is your first time to this site, please see the first post on <a href="http://www.logansbailey.com/2011/02/20/rails-3-blog-tutorial/">making your owns rails blog</a>.  Before we start with this weeks topics I made some basic CSS and formatting changes that can be seen <a href="https://github.com/baileylo/blog/commit/437f248cb3b3f2b6c27a6164d195c94aa6e870bb">here</a>.  Currently the blog displays dates in RFC format and only shows the authors email.  This week you&#8217;ll use Rails I8ln tools to build custom date formatting.  We&#8217;ll also extend Devise, allowing users to login with a user name.</p>
<h3 id="date_formatting">Custom Date Formatting</h3>
<p>There are two main theories to Date Formatting.  <a href="http://www.logansbailey.com/2010/10/22/custom-date-formatting-in-ruby-on-rails/">Building a time_format initializer</a> or adding date formats to your locales file.  Since date formats differ between regions it makes sense to place these formats in your locales file.</p>
<p>Open up <strong>config/locales/en.yml</strong>, <strong>app/view/posts/show.html.erb</strong>, and <strong>app/view/posts/index.html.erb</strong> and make <a href="https://github.com/baileylo/blog/commit/418137d6148d486f4fa70cea9984473e62848c62">these changes</a>.  In locales file, the format named &#8220;default&#8221; will be used if no format is specified.  In the view file, those are L&#8217;s that have been added prior to the dates. L is a default rails helper method for localize and will apply the localization for that data in our case a timestamp.  You can add as many differing formats as you&#8217;d like.  You can call these by using the following code</p>
<p><code>&lt;%= l Time.now, :format =&gt; :awesome %&gt;</code></p>
<p>A cheat sheet of all ruby date formats can be found <a href="http://cheat.errtheblog.com/s/strftime/">here</a>. If you would like more information on <strong>locale files</strong>, Ruby on Rails has a good <a href="http://guides.rubyonrails.org/i18n.html">guide</a> on it.</p>
<h3 id="usernames">Usernames</h3>
<p>Adding usernames is a breeze with <a href="https://github.com/plataformatec/devise">Devise</a>.  The first step to is create a migration to add the column.<br />
<code>$rails g migration addUsernameToUser username:string</code><br />
Open up the generated migration and make <a href="https://github.com/baileylo/blog/commit/febba4959370bee685447ed3994067d896a21df0">these changes</a> then run the migration.<br />
Since we plan to allow <strong>users</strong> to login using their <em>username</em> we&#8217;ve made it a unique key, the database will not allow more than 1 <strong>User</strong> to have the same <em>username</em>.  Now that the column is created, modify the <strong>User</strong> model to allow editing and validation of <em>username</em>.  We will also make sure that Devise is validating data in the forms. You can see the changes here, <a href="https://github.com/baileylo/blog/commit/ca041f693d00410d401bf75ff801f0b341f8b78e">user.rb</a></p>
<p>Now that our model and database are set to handle usernames, we have to make sure our views can handle them.  To do this we need to extend the default Devise views.  Run the following commands and then edit the files as seen <a href="https://github.com/baileylo/blog/commit/47f3750dfc0512236693a41d7c56ffb754dbc813">here</a>.<br />
<code>$ rails generate devise:views</code><br />
For more information about this as well as how to let user recover their passwords using username or email please see the <a href="https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign_in-using-their-username-or-email-address">Devise wiki</a>.<br />
Now that we can edit, login and register with usernames, lets display them on our page.  Edit post show and post index templates as seen here.</p>
<p>Check in next week were we will add comments to the posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logansbailey.com/2011/03/07/date-formatting-and-customizing-devise/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Authorization Using Devise</title>
		<link>http://www.logansbailey.com/2011/02/27/adding-authorization-using-devise/</link>
		<comments>http://www.logansbailey.com/2011/02/27/adding-authorization-using-devise/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 04:59:22 +0000</pubDate>
		<dc:creator>Logan Bailey</dc:creator>
				<category><![CDATA[Rails Tutorial Blog]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.logansbailey.com/?p=401</guid>
		<description><![CDATA[This will cover how to use Devise as your user authentication system. In previous posts I&#8217;ve used AuthLogic which is a good solution, I just find Devise simpler to use and implement. This will extend from my article Rails 3 &#8230;<p class="read-more"><a href="http://www.logansbailey.com/2011/02/27/adding-authorization-using-devise/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>This will cover how to use Devise as your user authentication system.  In previous posts I&#8217;ve used AuthLogic which is a good solution, I just find Devise simpler to use and implement.  This will extend from my article <a href="http://www.logansbailey.com/2011/02/20/rails-3-blog-tutorial/">Rails 3 Blog Tutorial</a>.   I&#8217;d highly suggest going through that tutorial, or you can run these commands.</p>
<p><code>git clone git@github.com:baileylo/blog.git<br />
git checkout -b blogCreated 0ba92371c2998caf362827987a82050708e9cd25<br />
</code></p>
<p>First add devise to your gemfile, <i>gem â€œDeviseâ€</i>.  Then run the follow commands:</p>
<p><code>$ bundle install<br />
$ rails generate devise:install<br />
</code><br />
This will install the Devise gem and set up the Devise modules. You will be prompted for 3 steps:</p>
<div id="gist-846956" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>Some setup you must do manually if you haven&#39;t yet:</div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>&nbsp;&nbsp;1. Setup default url options for your specific environment. Here is an</div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;example of development environment:</div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;config.action_mailer.default_url_options = { :host =&gt; &#39;localhost:3000&#39; }</div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This is a required Rails configuration. In production it must be the</div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;actual host of your application</div><div class='line' id='LC10'><br/></div><div class='line' id='LC11'>&nbsp;&nbsp;2. Ensure you have defined root_url to *something* in your config/routes.rb.</div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For example:</div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root :to =&gt; &quot;home#index&quot;</div><div class='line' id='LC15'><br/></div><div class='line' id='LC16'>&nbsp;&nbsp;3. Ensure you have flash messages in app/views/layouts/application.html.erb.</div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;For example:</div><div class='line' id='LC18'><br/></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p class=&quot;notice&quot;&gt;&lt;%= notice %&gt;&lt;/p&gt;</div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;p class=&quot;alert&quot;&gt;&lt;%= alert %&gt;&lt;/p&gt;</div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/846956/1a4ca54fbfc1ac56a9d69aabadf8370cd27a8ead/gistfile1.txt" style="float:right;">view raw</a>
            <a href="https://gist.github.com/846956#file_gistfile1.txt" style="float:right;margin-right:10px;color:#666">gistfile1.txt</a>
            <a href="https://gist.github.com/846956">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Do step 1, step 2 and 3 should already be done.  Once you have completed these steps run:</p>
<p><code>$ rails generate devise user</code></p>
<p>Open up your user model(app/models/users.rb).  You will see a comment at the top listing possible devise modules.  You can add and remove these as you wish.  For this tutorial we&#8217;ll only use: database_authenticatable, registerable, recoverable, rememberable, trackable.  Save the changes, and run:</p>
<p><code>$ rake db:migrate</code><br />
Now if you run â€œrake routesâ€ you will see a series of /users/ routes setup automatically by Devise.  Open up your application template, app/views/layout/application.html.erb and add the following code:<br />
<div id="gist-846957" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>&lt;div class=&quot;user-auth-nav&quot; style=&quot;float:right&quot;&gt;</div><div class='line' id='LC2'>&nbsp;&nbsp;&lt;% if user_signed_in? %&gt;</div><div class='line' id='LC3'>&nbsp;&nbsp;&lt;%= link_to(&#39;Edit registration&#39;, edit_user_registration_path) %&gt; | </div><div class='line' id='LC4'>&nbsp;&nbsp;&lt;%= link_to(&#39;Logout&#39;, destroy_user_session_path) %&gt; </div><div class='line' id='LC5'>&nbsp;&nbsp;&lt;% else %&gt;</div><div class='line' id='LC6'>&nbsp;&nbsp;&lt;%= link_to(&#39;Login&#39;, new_user_session_path)  %&gt; | </div><div class='line' id='LC7'>&nbsp;&nbsp;&lt;%= link_to(&#39;Register&#39;, new_user_registration_path)  %&gt;</div><div class='line' id='LC8'>&nbsp;&nbsp;&lt;% end %&gt;</div><div class='line' id='LC9'>&lt;/div&gt;</div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/846957/8c809d2d2660549c7b7dd7c4acb49d4ddef4baf5/gistfile1.txt" style="float:right;">view raw</a>
            <a href="https://gist.github.com/846957#file_gistfile1.txt" style="float:right;margin-right:10px;color:#666">gistfile1.txt</a>
            <a href="https://gist.github.com/846957">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>
<br />
<a href="https://github.com/baileylo/blog/commit/3fe407f3c48188f062277936137d818d8abd8462">diff</a> </p>
<p>Restart your rails server, and then reload your page.  You should see in the top right Login and Register links.  Feel free to create an account and play around with Devise&#8217;s built in authentication and user validation.</p>
<p>Now we need to associate a specific author with a specific post.  To do this will use another migration:</p>
<p><code>$ rails generate migrate addUserIdToPosts user_id:integer<br />
$ rake db:migrate<br />
</code></p>
<p>Rails migration generator will automatically read the migration name and realize that we&#8217;re adding the UserId column To the Posts table.  Now we need to make the relationships between the models in ruby.  Open up the user model(app/models/user.rb) and add â€œhas_many :postsâ€ within the class definition.  Now open the posts model (app/models/post.rb) and add â€œbelongs_to :userâ€ within the class definition.<br />
<a href="https://github.com/baileylo/blog/commit/50eb3c06e8d021e7ea325f0efcd3a02e8f7911a1">diff</a></p>
<p>So far now we&#8217;ve created user authentication system and added user to a post.  Open  your posts controller (app/controllers/posts_controller.rb) and add the following line at the top of your class, but inside the class definition<br />
before_filter :authenticate_user!, <img src='http://www.logansbailey.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly => [:edit, :update, :destroy, :create, :new]<br />
This will apply Devise&#8217;s built in function authenticate_user! When the actions edit, update, create, new, and destroy are called.  It will effectively require the user to be logged in to access these actions.  </p>
<p>Prior to a post being saved, we&#8217;re going to want to set the â€œposterâ€ to be the user who is currently signed in.  Devise provides the current_user helper which allows you access to the logged in user&#8217;s User object.  Change the â€œcreateâ€ action in the posts controller to look like this.</p>
<p><code>@post = Post.new(params[:post])<br />
@post.user = current_user<br />
</code><br />
<a href="https://github.com/baileylo/blog/commit/0ff08f4b682fb44a95121876a14e4fd5c4f9c2ba">diff</a> </p>
<p>This will assign the currently logged in user as the user for the post.  Lets clean up the views a little big.  Change your posts index.html.erb and show.html.erb files to look like this, app/views/posts/.<br />
<a href="https://github.com/baileylo/blog/commit/29091cfeb7726f982590db0de7a5106e775f91a9">diff</a></p>
<p>You may be getting error that reads: â€œundefined method `email&#8217; for nil:NilClassâ€œ.  These blogs were posted prior to having added the user migration.  You can add an if statement to skip the user data when a Post doesn&#8217;t have a related User Object.  But lets make a migration, run the following command<br />
<code>$ rails g migration insertUserInAllPosts</code></p>
<p>Open up the generated migration, and make the following changes
<link>.  We named the migration â€œinsertUserInAllPostsâ€, the name is up to you.  It is nice to have descriptive names for migrations; in the future you will waste less time figuring out what the migration does if it has a good name.<br />
<a href="https://github.com/baileylo/blog/commit/ec3ced2c0f24959fe90b7b1462a1f1fba0be3180">diff</a></p>
<p>You may have noticed that we have removed the links to edit posts for other users, but they can still edit posts if they go directly to the url.  To fix this we&#8217;ll use another â€œbefore_filterâ€.  Open up the posts controller, app/controllers/post_controller.rb, and make the following changes:<br />
<a href="https://github.com/baileylo/blog/commit/91450f7d7f90f56ce2aa9e5c01d8d0f4483656e5">diff</a></p>
<p>Now you have a full authorized blog.  Come back next week to see <a href="http://www.logansbailey.com/2011/03/07/date-formatting-and-customizing-devise/">user customizations</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logansbailey.com/2011/02/27/adding-authorization-using-devise/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Rails 3 Blog Tutorial</title>
		<link>http://www.logansbailey.com/2011/02/20/rails-3-blog-tutorial/</link>
		<comments>http://www.logansbailey.com/2011/02/20/rails-3-blog-tutorial/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 08:34:40 +0000</pubDate>
		<dc:creator>Logan Bailey</dc:creator>
				<category><![CDATA[Rails Tutorial Blog]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.logansbailey.com/?p=394</guid>
		<description><![CDATA[This tutorial will cover the creation of a personal blog using Ruby on Rails 3. This tutorial assumes that you have Sqlite3, and Rails gem installed. There will be other applications used but their installation is explained as is needed. &#8230;<p class="read-more"><a href="http://www.logansbailey.com/2011/02/20/rails-3-blog-tutorial/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>This tutorial will cover the creation of a personal blog using Ruby on Rails 3. This tutorial assumes that you have Sqlite3, and Rails gem installed.  There will be other applications used but their installation is explained as is needed.</p>
<p>The Blog:<br />
First lets create our rails application and come up with some basic starting blocks for our blog.<br />
<code>$ rails new blog<br />
$ cd blog<br />
$ rails generate scaffold post title:string body:text<br />
$ rake db:migrate<br />
$ rails -s</code></p>
<p>The first two commands create the base rails framework.  The next command is where you see a lot of the benefit of using ruby on rails.  It automatically created the migration files, model files, controller files, and view files for our new database object called â€œPostâ€.<br />
Migrations are how rails tracks schema changes in your database.  You can migrate the database up to a latest migration or roll down to a previous migration.  Rake db:migrate is the command to make the schema changes for the latest migration.  Rails -s creates a simple webbrick server; this server is good for development, but not production.</p>
<p>You should now be able to goto localhost:3000 where you will be greeted by a friend rails page.  Of course you probably don&#8217;t want your users to see this page so remove public/index.html.erb and add a new route, &#8216;root :to => â€œposts#showâ€ to your configs.rb, seen <a href="https://github.com/baileylo/blog/commit/1810b807beef6f65a135e262861e577881acd741">here</a>.</p>
<p>Once you reload your homepage you should see the friendly rails scaffolding.  Feel free to create your first post!</p>
<p><a href="http://www.logansbailey.com/2011/02/27/adding-authorization-using-devise/">Setting Up Authors on Your Blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.logansbailey.com/2011/02/20/rails-3-blog-tutorial/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title></title>
		<link>http://www.logansbailey.com/2010/12/30/387/</link>
		<comments>http://www.logansbailey.com/2010/12/30/387/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 01:04:11 +0000</pubDate>
		<dc:creator>Logan Bailey</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.logansbailey.com/2010/12/30/387/</guid>
		<description><![CDATA[Title: Iâ€™m Posting every day in 2011! Iâ€™ve decided I want to blog more. Rather than just thinking about doing it, Iâ€™m starting right now. I will be posting on this blog once a day / once a week for &#8230;<p class="read-more"><a href="http://www.logansbailey.com/2010/12/30/387/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Title: Iâ€™m Posting every day in 2011!</p>
<p>Iâ€™ve decided I want to blog more. Rather than just thinking about doing it, Iâ€™m starting right now.  I will be posting on this blog once a day / once a week for all of 2011.</p>
<p>I know it wonâ€™t be easy, but it might be fun, inspiring, awesome and wonderful. Therefore Iâ€™m promising to make use of The DailyPost, and the community of other bloggers with similiar goals, to help me along the way, including asking for help when I need it and encouraging others when I can.</p>
<p>If you already read my blog, I hope youâ€™ll encourage me with comments and likes, and good will along the way.</p>
<p>Signed,</p>
<p><Your Name Here></p>
]]></content:encoded>
			<wfw:commentRss>http://www.logansbailey.com/2010/12/30/387/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Lazy Loading</title>
		<link>http://www.logansbailey.com/2010/10/29/dynamic-lazy-loading/</link>
		<comments>http://www.logansbailey.com/2010/10/29/dynamic-lazy-loading/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 07:25:52 +0000</pubDate>
		<dc:creator>Logan Bailey</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[lazyloading]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.logansbailey.com/?p=383</guid>
		<description><![CDATA[Lazy loading allows the programmer to define a way to include PHP files at run time depending on class name requests.  Whenever a new class is referenced, statically or non statically, __autoload($classname) is called.  Finding an efficient and easy to manage system for defining class to file name structure can be a tedious chore.<p class="read-more"><a href="http://www.logansbailey.com/2010/10/29/dynamic-lazy-loading/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>While reading a blog post the other day about the <a href="http://terrychay.com/article/autoloading-and-lazy-loading.shtml">benefits of lazy loading</a>, I took a look at one of my own code bases and thought about how it could benefit from lazy loading.  A majority of tables in the database where had their own specific class file, some classes were group in the same file.  Other classes were grouped in subfolders.  All of these separate files were in one directory models, which was included on every page load.  This ended up being some 150 different files and 10 megabytes of parsed code.  This definitely seemed like an area for improvement.<br />
Given the mangled naming structure using a naming schema was immediately ruled out of consideration.  I next thought about creating a map, the downside to this was map maintenance.  I hate having to do stuff in 3 places, add the table to the database, create the php file, and then add it to the map.  I thought there must be an easier way to do this, and there was scripted model map generation.<br />
Since my code base could was already completely able to load every model with out a problem there were three things left to do.</p>
<ol>
<li>Load the code base and figure out which classes were default to php and which were my own.</li>
<li>Figure out what file each class was declared in</li>
<li>Store the data to a flat file for later reading.</li>
</ol>
<h3>1. Figuring Out Whose Class It Is:</h3>
<p>To figure out which classes were mind and which were natively part of php is a rather simple task using the <a href="http://php.net/manual/en/function.get-declared-classes.php">get_declared_classes() functio</a>n I was able to determine which classes were native to php.  After completely loading the code base, I ran the function again.  The difference of the initial run and the second run is my defined classes.</p>
<h3>2. Where Was It Declared:</h3>
<p>To figure out where each class is declared you use PHP reflection.<br />
<div id="gist-653078" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="k">foreach</span><span class="p">(</span><span class="nv">$class_list</span> <span class="k">as</span> <span class="nv">$classname</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$reflector</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ReflectionClass</span><span class="p">(</span><span class="nv">$classname</span><span class="p">);</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$ini_config_data</span><span class="p">[</span><span class="nx">strtolower</span><span class="p">(</span><span class="nv">$classname</span><span class="p">)]</span> <span class="o">=</span> <span class="nv">$reflector</span><span class="o">-&gt;</span><span class="na">getFileName</span><span class="p">();</span></div><div class='line' id='LC6'><span class="p">}</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'><span class="cp">?&gt;</span><span class="x"></span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/653078/583353a3aa1394bcf7100bdb25c15a16997681d6/gistfile1.php" style="float:right;">view raw</a>
            <a href="https://gist.github.com/653078#file_gistfile1.php" style="float:right;margin-right:10px;color:#666">gistfile1.php</a>
            <a href="https://gist.github.com/653078">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>
<br />
Now ini_cofig_data is a hash of classname => absolute/path/to/class.php</p>
<h3>3. How To Store It:</h3>
<p>Incase you couldn&#8217;t guess I used an ini file.  PHP has native ini parsing to array (<a href="http://us2.php.net/parse_ini_file">parse_ini_file</a>) so the read is extremely simple.  The write ends up being rather simple as well.<br />
<div id="gist-653075" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><span class="nv">$fp</span> <span class="o">=</span> <span class="nb">fopen</span><span class="p">(</span><span class="s1">&#39;object_map.ini&#39;</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">);</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'><span class="k">foreach</span><span class="p">(</span><span class="nv">$ini_config_data</span> <span class="k">as</span> <span class="nv">$class</span> <span class="o">=&gt;</span> <span class="nv">$filename</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$write</span> <span class="o">=</span> <span class="nv">$class</span> <span class="o">.</span> <span class="s1">&#39; = &#39;</span> <span class="o">.</span> <span class="nv">$filename</span> <span class="o">.</span> <span class="nx">PHP_EOL</span><span class="p">;</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">fwrite</span><span class="p">(</span><span class="nv">$fp</span><span class="p">,</span> <span class="nv">$write</span><span class="p">,</span> <span class="nb">strlen</span><span class="p">(</span><span class="nv">$write</span><span class="p">));</span></div><div class='line' id='LC7'><span class="p">}</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'><span class="nb">fclose</span><span class="p">(</span><span class="nv">$fp</span><span class="p">);</span></div><div class='line' id='LC10'><span class="cp">?&gt;</span><span class="x"></span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/653075/0eba671bf2520a72c2b0b177eb358a2fd870a37c/gistfile1.php" style="float:right;">view raw</a>
            <a href="https://gist.github.com/653075#file_gistfile1.php" style="float:right;margin-right:10px;color:#666">gistfile1.php</a>
            <a href="https://gist.github.com/653075">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>
</p>
<h3>Writing __autoload:</h3>
<p>The autoload function is very straight forward, it takes 1 parameter the name of the class to load.  We must look this up from are ini array and load it.  The code could look like this:<br />
<div id="gist-653077" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;?php</span></div><div class='line' id='LC2'><span class="nv">$model_object</span> <span class="o">=</span> <span class="nb">parse_ini_file</span><span class="p">(</span><span class="s1">&#39;object_map.ini&#39;</span><span class="p">);</span></div><div class='line' id='LC3'><span class="k">function</span> <span class="nf">__autoload</span><span class="p">(</span><span class="nv">$class_name</span><span class="p">)</span> <span class="p">{</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">global</span> <span class="nv">$model_object</span><span class="p">;</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nv">$class_name</span> <span class="o">=</span> <span class="nx">strtolower</span><span class="p">(</span><span class="nv">$class_name</span><span class="p">);</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nb">isset</span><span class="p">(</span><span class="nv">$model_object</span><span class="p">[</span><span class="nv">$class_name</span><span class="p">]))</span> <span class="p">{</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">exit</span><span class="p">(</span><span class="s1">&#39;invalid class name&#39;</span><span class="p">);</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="p">}</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">require_once</span><span class="p">(</span><span class="nv">$model_object</span><span class="p">[</span><span class="nv">$class_name</span><span class="p">]);</span></div><div class='line' id='LC11'><span class="p">}</span></div><div class='line' id='LC12'><span class="cp">?&gt;</span><span class="x"></span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/653077/561115be85afd07353f45957fcc74a00b721ee24/gistfile1.php" style="float:right;">view raw</a>
            <a href="https://gist.github.com/653077#file_gistfile1.php" style="float:right;margin-right:10px;color:#666">gistfile1.php</a>
            <a href="https://gist.github.com/653077">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>
<br />
There is a bit of hack to get model_object global, but you can add it as an attribute to your framework that is returned via a static call?  Just don&#8217;t read the file every time</p>
<p>Now after I create a new model, I simply rerun the script and I&#8217;m good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logansbailey.com/2010/10/29/dynamic-lazy-loading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Date Formatting in Ruby on Rails</title>
		<link>http://www.logansbailey.com/2010/10/22/custom-date-formatting-in-ruby-on-rails/</link>
		<comments>http://www.logansbailey.com/2010/10/22/custom-date-formatting-in-ruby-on-rails/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 20:12:41 +0000</pubDate>
		<dc:creator>Logan Bailey</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[ror]]></category>

		<guid isPermaLink="false">http://www.logansbailey.com/?p=372</guid>
		<description><![CDATA[Ruby on Rails offers a couple different standardized date formats which can be really helpful. I&#8217;m personally a huge fan of :db, I hate looking it up all the time. But you may be wondering how to create a custom &#8230;<p class="read-more"><a href="http://www.logansbailey.com/2010/10/22/custom-date-formatting-in-ruby-on-rails/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Ruby on Rails offers a couple different standardized date formats which can be really helpful. I&#8217;m personally a huge fan of :db, I hate looking it up all the time.  But you may be wondering how to create a custom date format.  Easy enough, open and create a new file(edit if you already have it) <em>config/initializers/time_formats.rb</em>.<br />
In this file we&#8217;ll keep all of our custom date formats.<br />
Add the following code:<br />
<code><br />
Time::DATE_FORMATS[:slashy_format] = "%m/%d/%Y"<br />
DATE::DATE_FORMATS[:slashy_format] = "%m/%d/%Y"</code><br />
Restart your server and there you have it.<br />
This format can accessed via<br />
<code>@something.date.to_formatted_s(:slasy_format)</code></p>
<p>There&#8217;s not really much else to it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.logansbailey.com/2010/10/22/custom-date-formatting-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Setup Double Foreign Keys</title>
		<link>http://www.logansbailey.com/2010/10/20/setup-double-foreign-keys/</link>
		<comments>http://www.logansbailey.com/2010/10/20/setup-double-foreign-keys/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 07:35:21 +0000</pubDate>
		<dc:creator>Logan Bailey</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.logansbailey.com/?p=363</guid>
		<description><![CDATA[This is how to create a model relationship in Ruby on Rails where one model, message, has two foreign keys to another model, user. The sql tables are defined below, and is given the solution in Ruby and how to &#8230;<p class="read-more"><a href="http://www.logansbailey.com/2010/10/20/setup-double-foreign-keys/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>This is how to create a model relationship in Ruby on Rails where one model, message, has two foreign keys to another model, user.  The sql tables are defined below, and is given the solution in Ruby and how to retrieve the values.</p>
<p><code><br />
create table `user`(<br />
&nbsp;&nbsp;&nbsp;&nbsp;`id` INT(10) PRIMARY KEY,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`name` VARCHAR(25)<br />
);<br />
create table `message` (<br />
&nbsp;&nbsp;&nbsp;&nbsp;`id` INT(10) PRIMARY KEY,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`author_user_id` INT(10),<br />
&nbsp;&nbsp;&nbsp;&nbsp;`recipient_user_id` INT(10),<br />
&nbsp;&nbsp;&nbsp;&nbsp;`subject` VARCHAR(250)<br />
);<br />
</code></p>
<p>To create the correct ORM relations use the following ruby code:</p>
<p><code>class Message &lt; ActiveRecord::Base<br />
&nbsp;&nbsp;&nbsp;&nbsp;belongs_to :author, :class_name =&gt; "User", :foreign_key =&gt; "author_user_id"<br />
&nbsp;&nbsp;&nbsp;&nbsp;belongs_to :recipient, :class_name =&gt; "User", :foreign_key =&gt; "recipient_user_id"<br />
end<br />
</code></p>
<p>With the above code you can access user data via</p>
<p><code>&lt;%= @message.author.name %&gt;</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.logansbailey.com/2010/10/20/setup-double-foreign-keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Build Forums in Rails 3</title>
		<link>http://www.logansbailey.com/2010/10/19/how-to-build-forums-in-rails-3/</link>
		<comments>http://www.logansbailey.com/2010/10/19/how-to-build-forums-in-rails-3/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 06:59:37 +0000</pubDate>
		<dc:creator>Logan Bailey</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[forum]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ror]]></category>

		<guid isPermaLink="false">http://www.logansbailey.com/?p=327</guid>
		<description><![CDATA[This tutorial will go over the basic steps to create a forums app. The forums will extend from my previous blog post about integrating Rails 3 with AuthLogic. If you are new to rails I&#8217;d high recommend reading it, otherwise &#8230;<p class="read-more"><a href="http://www.logansbailey.com/2010/10/19/how-to-build-forums-in-rails-3/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>This tutorial will go over the basic steps to create a forums app.  The forums will extend from my previous blog post about <a href="http://www.logansbailey.com/2010/10/06/how-to-setup-authlogic-in-rails-3/">integrating Rails 3 with AuthLogic</a>.  If you are new to rails I&#8217;d high recommend reading it, otherwise continue.  First download the source code from the AuthLogic App and move the code to more logically named directory for this project.</p>
<p><code><br />
$ mkdir forums<br />
$ git init<br />
$ git clone git://github.com/baileylo/login_app.git forums<br />
$ cd forums<br />
$ rake db:migrate<br />
$ rails -s<br />
</code></p>
<p>Feel free to verify that everything is working, you should be able to register and login at /users.</p>
<h3>The Backend</h3>
<p>Rails has reserved &#8220;thread&#8221; has a model name so this will create a weird model name but the other two model names are straight forward: Board, Conversation, Comment.<br/></p>
<p>Board is a set of boards, groupings of conversations.  Conversation, probably more commonly referred to as &#8220;Thread&#8221;, is list of Comments made by users.  In our forum we&#8217;ll keep it simple,  A Board will contain only a name and an id, a Conversation will belong to a board.  A Conversation will have a title and a creating user.  Comments will have only a body a posting user and a reference to the conversation they belong to.</p>
<p><code><br />
$ rails g scaffold board id:integer title:string<br />
$ rails g scaffold conversation id:integer title:string board_id:integer user_id:integer<br />
$ rails g scaffold comment id:integer user_id:integer conversation_id:integer body:text<br />
</code></p>
<p>This created all the controllers, views, models, and migration files needed.  Open up the three migration files created, and edit them to look as follows.</p>
<div id="gist-627737" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="k">class</span> <span class="nc">CreateBoards</span> <span class="o">&lt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Migration</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">up</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">create_table</span> <span class="ss">:boards</span> <span class="k">do</span> <span class="o">|</span><span class="n">t</span><span class="o">|</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">integer</span> <span class="ss">:id</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">string</span> <span class="ss">:title</span><span class="p">,</span> <span class="ss">:limit</span> <span class="o">=&gt;</span> <span class="mi">50</span></div><div class='line' id='LC6'><br/></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">timestamps</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC10'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'>&nbsp;&nbsp;<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">down</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">drop_table</span> <span class="ss">:boards</span></div><div class='line' id='LC14'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC15'><span class="k">end</span></div><div class='line' id='LC16'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/627737/f0d3d2548e7c37f9f8b256ec41ef3be291c1f11c/create_boards.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/627737#file_create_boards.rb" style="float:right;margin-right:10px;color:#666">create_boards.rb</a>
            <a href="https://gist.github.com/627737">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><br/></div><div class='line' id='LC2'><span class="k">class</span> <span class="nc">CreateComments</span> <span class="o">&lt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Migration</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">up</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">create_table</span> <span class="ss">:comments</span> <span class="k">do</span> <span class="o">|</span><span class="n">t</span><span class="o">|</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">integer</span> <span class="ss">:id</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">integer</span> <span class="ss">:user_id</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">integer</span> <span class="ss">:conversation_id</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">text</span> <span class="ss">:body</span></div><div class='line' id='LC9'><br/></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">timestamps</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">add_index</span> <span class="ss">:comments</span><span class="p">,</span> <span class="ss">:conversation_id</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">add_index</span> <span class="ss">:comments</span><span class="p">,</span> <span class="ss">:user_id</span></div><div class='line' id='LC14'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC15'><br/></div><div class='line' id='LC16'>&nbsp;&nbsp;<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">down</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">drop_table</span> <span class="ss">:comments</span></div><div class='line' id='LC18'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC19'><span class="k">end</span></div><div class='line' id='LC20'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/627737/ebb7b148b0999c9241a9bc7b898680b0f6824fa0/create_comments.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/627737#file_create_comments.rb" style="float:right;margin-right:10px;color:#666">create_comments.rb</a>
            <a href="https://gist.github.com/627737">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="k">class</span> <span class="nc">CreateConversations</span> <span class="o">&lt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Migration</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">up</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">create_table</span> <span class="ss">:conversations</span> <span class="k">do</span> <span class="o">|</span><span class="n">t</span><span class="o">|</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">integer</span> <span class="ss">:id</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">string</span> <span class="ss">:title</span><span class="p">,</span> <span class="ss">:limit</span> <span class="o">=&gt;</span> <span class="mi">50</span></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">integer</span> <span class="ss">:board_id</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">integer</span> <span class="ss">:user_id</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">t</span><span class="o">.</span><span class="n">timestamps</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">add_index</span> <span class="ss">:conversations</span><span class="p">,</span> <span class="ss">:board_id</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">add_index</span> <span class="ss">:conversations</span><span class="p">,</span> <span class="ss">:user_id</span></div><div class='line' id='LC13'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'>&nbsp;&nbsp;<span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">down</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">drop_table</span> <span class="ss">:conversations</span></div><div class='line' id='LC17'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC18'><span class="k">end</span></div><div class='line' id='LC19'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/627737/7e3064582931ba22565afb2de816eee05c5e0676/create_conversations.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/627737#file_create_conversations.rb" style="float:right;margin-right:10px;color:#666">create_conversations.rb</a>
            <a href="https://gist.github.com/627737">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>These changes add indexes to our Conversations and Comments tables. These will add a much needed performance boost when querying the database.  They also added size limitations to board.title and conversation.title of 50 characters.</p>
<p>Now create the database tables by running:</p>
<p><code><br />
$ rake db:migrate<br />
</code></p>
<h3>Some Quick Backend Additions</h3>
<p>Feel free to browse around the site, you&#8217;ll notice all the forms work correctly, but none of the objects are linked together.  To tell active record that these models are linked we must edit the Model Classes.<br />
Open up your newly created model classes and edit them to look like this:</p>
<div id="gist-627747" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="k">class</span> <span class="nc">Board</span> <span class="o">&lt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="n">has_many</span> <span class="ss">:conversations</span></div><div class='line' id='LC3'><span class="k">end</span></div><div class='line' id='LC4'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/627747/fccfbff4a8d1192053faa1e065b5f519d435e6cb/board.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/627747#file_board.rb" style="float:right;margin-right:10px;color:#666">board.rb</a>
            <a href="https://gist.github.com/627747">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="k">class</span> <span class="nc">Comment</span> <span class="o">&lt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="n">belongs_to</span> <span class="ss">:conversation</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="n">belongs_to</span> <span class="ss">:user</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="n">validates_presence_of</span> <span class="ss">:body</span></div><div class='line' id='LC5'><span class="k">end</span></div><div class='line' id='LC6'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/627747/458d502605fe3e93c7918a774231bb641c27872a/comment.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/627747#file_comment.rb" style="float:right;margin-right:10px;color:#666">comment.rb</a>
            <a href="https://gist.github.com/627747">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="k">class</span> <span class="nc">Conversation</span> <span class="o">&lt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="n">has_many</span> <span class="ss">:comments</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="n">belongs_to</span> <span class="ss">:user</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="n">belongs_to</span> <span class="ss">:board</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="n">validates_presence_of</span> <span class="ss">:title</span></div><div class='line' id='LC6'><span class="k">end</span></div><div class='line' id='LC7'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/627747/9c961a2aa7afaba91b943db639ffcf7216ea5aaa/conversation.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/627747#file_conversation.rb" style="float:right;margin-right:10px;color:#666">conversation.rb</a>
            <a href="https://gist.github.com/627747">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>In this we see two very important ideas.  We&#8217;ve added form validation as well as ORM hooks that define relationships between our models. In board.rb and conversation.rb we added <em>has_many :conversations</em> and <em>has_many :comments</em>, respectively, this informs Rails these are 1 to many relationships.  You can see the rails docs for <a href="http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many">has_many  here</a>.  This makes the relationship from one conversation to many comments.  In conversation.rb and comments.rb you can see the belongs_to function, this function tells rails that these objects belong to another specific object, you can see the docs for <a href="http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html#method-i-belongs_t">belongs_to here</a>.<br />
<em>validates_presence_of</em> is called when a save, update, or create are called on an object.  This function makes sure that there is data stored in these member variables.  We specified that conversation.title and comment.body must be required, we don&#8217;t want any empty posts.  Board.title was purposefully skipped, it is not for general use.</p>
<p>If you navigate to your conversations page: http://localhost:3000/conversations and try to create a message, not including a title, you will get a nice error saying that it is a required field.  You will how ever notice that you can make this field as long as you like even though we specified it should only be 50 characters long.  Lets fix this, add the following line of code to your conversation.rb file:</p>
<p><code><br />
validates_length_of :title, :maximum=&gt;50<br />
</code></p>
<p>If you try again you will see an error message stating that the &#8220;the input must be less than 50 characters&#8221;.</p>
<p>If you&#8217;ve created any data, you may want to clean it up now, it may cause problems later in this demonstration.</p>
<h3>Routes!</h3>
<p>Now that we have the backend in order, lets create the routes needed to use this message board. Open up your config/routes.rb file and change it to look like this:</p>
<div id="gist-627764" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="no">LoginApp</span><span class="o">::</span><span class="no">Application</span><span class="o">.</span><span class="n">routes</span><span class="o">.</span><span class="n">draw</span> <span class="k">do</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="n">resources</span> <span class="ss">:boards</span> <span class="k">do</span> </div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">resources</span> <span class="ss">:conversations</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC6'><br/></div><div class='line' id='LC7'>&nbsp;&nbsp;<span class="n">root</span> <span class="ss">:to</span> <span class="o">=&gt;</span> <span class="s2">&quot;boards#index&quot;</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>&nbsp;&nbsp;<span class="n">resources</span> <span class="ss">:users</span><span class="p">,</span> <span class="ss">:user_sessions</span></div><div class='line' id='LC10'>&nbsp;&nbsp;<span class="n">match</span> <span class="s1">&#39;login&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;user_sessions#new&#39;</span><span class="p">,</span> <span class="ss">:as</span> <span class="o">=&gt;</span> <span class="ss">:login</span></div><div class='line' id='LC11'>&nbsp;&nbsp;<span class="n">match</span> <span class="s1">&#39;logout&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;user_sessions#destroy&#39;</span><span class="p">,</span> <span class="ss">:as</span> <span class="o">=&gt;</span> <span class="ss">:logout</span></div><div class='line' id='LC12'><span class="k">end</span></div><div class='line' id='LC13'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/627764/f05517d16cb6a6531e1d90a95be7f335a9cd4f5b/routes.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/627764#file_routes.rb" style="float:right;margin-right:10px;color:#666">routes.rb</a>
            <a href="https://gist.github.com/627764">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Delete your <em>public/index.html</em> file, it&#8217;s no longer needed.<br/><br />
Now localhost:3000/ will display a list of your Boards, instead of the rails information page.<br/><br />
In your console type:</p>
<p><code><br />
$ rake routes<br />
</code></p>
<p>This is a list of every url that your app can handle, the most important are the top few.  We&#8217;ve now created a url hierarchy.  All of a conversations will be listed by /boards/:board_id/conversations/:id.</p>
<h3>Jumping into the view</h3>
<p>Our site looks okay, but lets try and spiff it up a bit.  Open up your views/layouts/index.html and change it to look like:</p>
<div id="gist-627776" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;!DOCTYPE html&gt;</span></div><div class='line' id='LC2'><span class="nt">&lt;html&gt;</span></div><div class='line' id='LC3'><span class="nt">&lt;head&gt;</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="nt">&lt;title&gt;</span>Rails Message Boards<span class="nt">&lt;/title&gt;</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">stylesheet_link_tag</span> <span class="ss">:all</span> <span class="cp">%&gt;</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">javascript_include_tag</span> <span class="ss">:defaults</span> <span class="cp">%&gt;</span></div><div class='line' id='LC7'>&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">csrf_meta_tag</span> <span class="cp">%&gt;</span></div><div class='line' id='LC8'><span class="nt">&lt;/head&gt;</span></div><div class='line' id='LC9'><span class="nt">&lt;body&gt;</span></div><div class='line' id='LC10'><br/></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">&quot;wrapper&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">&quot;top_nav&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;h1&gt;</span><span class="cp">&lt;%=</span> <span class="n">image_tag</span><span class="p">(</span><span class="s2">&quot;rails.png&quot;</span><span class="p">,</span> <span class="ss">:size</span> <span class="o">=&gt;</span> <span class="s1">&#39;50x50&#39;</span><span class="p">)</span> <span class="cp">%&gt;</span> Rails Boards<span class="nt">&lt;/h1&gt;</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="k">if</span> <span class="n">current_user</span> <span class="cp">%&gt;</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s2">&quot;Edit Profile&quot;</span><span class="p">,</span> <span class="n">edit_user_path</span><span class="p">(</span><span class="n">current_user</span><span class="o">.</span><span class="n">id</span><span class="p">)</span><span class="cp">%&gt;</span> |</div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s2">&quot;Logout&quot;</span><span class="p">,</span> <span class="ss">:logout</span><span class="cp">%&gt;</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="k">else</span> <span class="cp">%&gt;</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s2">&quot;Register&quot;</span><span class="p">,</span> <span class="n">new_user_path</span><span class="cp">%&gt;</span> | </div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s2">&quot;Login&quot;</span><span class="p">,</span> <span class="ss">:login</span> <span class="cp">%&gt;</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;bclear&quot;</span><span class="nt">&gt;&lt;/div&gt;</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/div&gt;</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">&quot;content&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="k">yield</span> <span class="cp">%&gt;</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/div&gt;</span></div><div class='line' id='LC29'><br/></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">&quot;footer&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC31'><br/></div><div class='line' id='LC32'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/div&gt;</span></div><div class='line' id='LC33'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/div&gt;</span></div><div class='line' id='LC34'><span class="nt">&lt;/body&gt;</span></div><div class='line' id='LC35'><span class="nt">&lt;/html&gt;</span></div><div class='line' id='LC36'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/627776/0b2a08953114eb6efae2b481f48d8ee954233f5a/layout.html.erb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/627776#file_layout.html.erb" style="float:right;margin-right:10px;color:#666">layout.html.erb</a>
            <a href="https://gist.github.com/627776">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Create a new file in public/stylesheets called style.css and copy this style sheet, <a href="http://gist.github.com/627780">http://gist.github.com/627780</a></p>
<p>.</p>
<p>At localhost:3000 you should be greeted by a much friendlier page:<br />
<img class="alignnone size-full wp-image-331" title="after_style" src="http://www.logansbailey.com/wp-content/uploads/2010/10/after_style.jpg" alt="after_style" width="882" height="550" /></p>
<p>If you haven&#8217;t created a board yet, feel free to create one now using the &#8220;Create Board&#8221; Link at the bottom of the page.  You can put in you own ID if you want, if you leave it blank rails will auto increment the id.</p>
<p>Lets fix up that homepage a bit and make it look slightly more professional.  Open up views/boards/index.html, and change it to look like this:</p>
<div id="gist-627784" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nt">&lt;h1</span> <span class="na">id=</span><span class="s">&quot;page_title&quot;</span><span class="nt">&gt;</span>Message Boards<span class="nt">&lt;/h1&gt;</span></div><div class='line' id='LC2'><span class="nt">&lt;p</span> <span class="na">id=</span><span class="s">&quot;notice&quot;</span><span class="nt">&gt;</span><span class="cp">&lt;%=</span> <span class="n">notice</span> <span class="cp">%&gt;</span><span class="nt">&lt;/p&gt;</span></div><div class='line' id='LC3'><span class="nt">&lt;table&gt;</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="nt">&lt;tr&gt;</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;th</span> <span class="na">align=</span><span class="s">&quot;left&quot;</span><span class="nt">&gt;</span>Title<span class="nt">&lt;/th&gt;</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="nt">&lt;/tr&gt;</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'><span class="cp">&lt;%</span> <span class="vi">@boards</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">board</span><span class="o">|</span> <span class="cp">%&gt;</span></div><div class='line' id='LC9'>&nbsp;&nbsp;<span class="nt">&lt;tr&gt;</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;td&gt;</span><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="n">board</span><span class="o">.</span><span class="n">title</span><span class="p">,</span> <span class="n">board</span> <span class="cp">%&gt;</span><span class="nt">&lt;/td&gt;</span></div><div class='line' id='LC11'>&nbsp;&nbsp;<span class="nt">&lt;/tr&gt;</span></div><div class='line' id='LC12'><span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span></div><div class='line' id='LC13'><span class="nt">&lt;/table&gt;</span></div><div class='line' id='LC14'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/627784/507dcd753194b67d59b15b3b1ef9346a1ae20d72/index.html.erb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/627784#file_index.html.erb" style="float:right;margin-right:10px;color:#666">index.html.erb</a>
            <a href="https://gist.github.com/627784">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Now that our landing page looks decent, lets see what happens when we view our message board:</p>
<p><img src="http://www.logansbailey.com/wp-content/uploads/2010/10/board_view_start.jpg" alt="board_view_start" title="board_view_start" width="882" height="550" class="alignnone size-full wp-image-332" /></p>
<p>Not what anybody envisions a messageboard to be looking like, lets make some quick cosmetic changes before moving into the controller.  Open up app/views/boards/show.html.erb and make it the following changes:</p>
<div id="gist-627788" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nt">&lt;h1</span> <span class="na">id=</span><span class="s">&quot;page_title&quot;</span><span class="nt">&gt;</span><span class="cp">&lt;%=</span> <span class="vi">@board</span><span class="o">.</span><span class="n">title</span> <span class="cp">%&gt;</span><span class="nt">&lt;/h1&gt;</span></div><div class='line' id='LC2'><span class="nt">&lt;p</span> <span class="na">id=</span><span class="s">&quot;notice&quot;</span><span class="nt">&gt;</span><span class="cp">&lt;%=</span> <span class="n">notice</span> <span class="cp">%&gt;</span><span class="nt">&lt;/p&gt;</span></div><div class='line' id='LC3'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s1">&#39;Rails Boards&#39;</span><span class="p">,</span> <span class="n">boards_path</span> <span class="cp">%&gt;</span> <span class="ni">&amp;gt;</span> <span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="vi">@board</span><span class="o">.</span><span class="n">title</span><span class="p">,</span> <span class="vi">@board</span> <span class="cp">%&gt;</span> <span class="nt">&lt;br</span> <span class="nt">/&gt;</span></div><div class='line' id='LC4'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s1">&#39;Post New Message&#39;</span><span class="p">,</span> <span class="n">new_board_conversation_url</span><span class="p">(</span><span class="vi">@board</span><span class="p">)</span> <span class="cp">%&gt;</span></div><div class='line' id='LC5'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/627788/6bfe5e2297444c18b0463600a6be6d3d0a4fba45/shows.html.erb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/627788#file_shows.html.erb" style="float:right;margin-right:10px;color:#666">shows.html.erb</a>
            <a href="https://gist.github.com/627788">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>As you can see here we added a &#8220;Post New Message&#8221; link, the url function did not come out of thin air, if you run rake routes again.  You&#8217;ll see there is a path named &#8220;new_board_conversation&#8221;, you can use any of those as a url by appending _url or _path to them.</p>
<p>If you click on the link to post new message you&#8217;ll get &#8220;No Routes Matches&#8221; error.  We&#8217;ll fix that in a minute, but first lets make some adjustments to our conversation controller, open up app/controllers/conversation.rb and make the follow changes:</p>
<div id="gist-627798" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="k">class</span> <span class="nc">ConversationsController</span> <span class="o">&lt;</span> <span class="no">ApplicationController</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="n">before_filter</span> <span class="ss">:load_board</span></div><div class='line' id='LC3'>&nbsp;&nbsp;</div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="c1"># GET /conversations</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="c1"># GET /conversations.xml</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">index</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@conversations</span> <span class="o">=</span> <span class="no">Conversation</span><span class="o">.</span><span class="n">all</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">respond_to</span> <span class="k">do</span> <span class="o">|</span><span class="nb">format</span><span class="o">|</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">format</span><span class="o">.</span><span class="n">html</span> <span class="c1"># index.html.erb</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">format</span><span class="o">.</span><span class="n">xml</span>  <span class="p">{</span> <span class="n">render</span> <span class="ss">:xml</span> <span class="o">=&gt;</span> <span class="vi">@conversations</span> <span class="p">}</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC13'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'>&nbsp;&nbsp;<span class="c1"># CODE REMOVED FOR CLARITY SAKE</span></div><div class='line' id='LC16'>&nbsp;&nbsp;</div><div class='line' id='LC17'>&nbsp;&nbsp;<span class="kp">private</span></div><div class='line' id='LC18'>&nbsp;&nbsp;</div><div class='line' id='LC19'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">load_board</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="no">Board</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:board_id</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@board</span> <span class="o">=</span> <span class="no">Board</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:board_id</span><span class="o">]</span><span class="p">);</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">unless</span> <span class="vi">@board</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">redirect_to</span><span class="p">(</span><span class="n">boards_path</span><span class="p">,</span> <span class="ss">:notice</span> <span class="o">=&gt;</span><span class="s2">&quot;Please specify a valid board&quot;</span><span class="p">)</span></div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC27'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC28'><span class="k">end</span></div><div class='line' id='LC29'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/627798/d02bf461d1bd341e2bada9fa2f49384ce53f42ec/conversation.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/627798#file_conversation.rb" style="float:right;margin-right:10px;color:#666">conversation.rb</a>
            <a href="https://gist.github.com/627798">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>We added a private function that tries to load a Board off a passed in parameter.  This function will be called on any page that goes through this controller.</p>
<h3>Modify AuthLogic</h3>
<p>If you have tried to login you may have noticed that we skipped a step.  The login, logout, and register functions are not exactly tied to our application.  To fix this we need to correct links in the views and redirect the controllers.  While we&#8217;re doing this it will be a good time to remove functions that the app won&#8217;t be using.  Open up <em>app/controllers/users_controller.rb</em> and edit it to look like so:</p>
<div id="gist-635885" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="k">class</span> <span class="nc">UsersController</span> <span class="o">&lt;</span> <span class="no">ApplicationController</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="c1"># GET /users/1</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">show</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@user</span> <span class="o">=</span> <span class="no">User</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:id</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'>&nbsp;&nbsp;<span class="c1"># GET /users/new</span></div><div class='line' id='LC9'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">new</span>    </div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@user</span> <span class="o">=</span> <span class="no">User</span><span class="o">.</span><span class="n">new</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="n">current_user</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">redirect_to</span><span class="p">(</span><span class="n">homepage_url</span><span class="p">,</span> <span class="ss">:notice</span> <span class="o">=&gt;</span> <span class="s1">&#39;Already registered&#39;</span><span class="p">)</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC15'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC16'><br/></div><div class='line' id='LC17'>&nbsp;&nbsp;<span class="c1"># GET /users/1/edit</span></div><div class='line' id='LC18'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">edit</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">is_user</span></div><div class='line' id='LC20'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC21'><br/></div><div class='line' id='LC22'>&nbsp;&nbsp;<span class="c1"># POST /users</span></div><div class='line' id='LC23'>&nbsp;&nbsp;<span class="c1"># POST /users.xml</span></div><div class='line' id='LC24'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">create</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@user</span> <span class="o">=</span> <span class="no">User</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:user</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@user_session</span> <span class="o">=</span> <span class="no">UserSession</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:user</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC27'><br/></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">respond_to</span> <span class="k">do</span> <span class="o">|</span><span class="nb">format</span><span class="o">|</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="vi">@user</span><span class="o">.</span><span class="n">save</span> <span class="o">&amp;&amp;</span> <span class="vi">@user_session</span><span class="o">.</span><span class="n">save</span></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">format</span><span class="o">.</span><span class="n">html</span> <span class="p">{</span> <span class="n">redirect_to</span><span class="p">(</span><span class="n">homepage_url</span><span class="p">,</span> <span class="ss">:notice</span> <span class="o">=&gt;</span> <span class="s1">&#39;Registration successfull.&#39;</span><span class="p">)</span> <span class="p">}</span></div><div class='line' id='LC31'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">else</span></div><div class='line' id='LC32'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">format</span><span class="o">.</span><span class="n">html</span> <span class="p">{</span> <span class="n">render</span> <span class="ss">:action</span> <span class="o">=&gt;</span> <span class="s2">&quot;new&quot;</span> <span class="p">}</span></div><div class='line' id='LC33'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC34'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC35'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC36'><br/></div><div class='line' id='LC37'>&nbsp;&nbsp;<span class="c1"># PUT /users/1</span></div><div class='line' id='LC38'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">update</span></div><div class='line' id='LC39'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">is_user</span></div><div class='line' id='LC40'><br/></div><div class='line' id='LC41'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">respond_to</span> <span class="k">do</span> <span class="o">|</span><span class="nb">format</span><span class="o">|</span></div><div class='line' id='LC42'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="vi">@user</span><span class="o">.</span><span class="n">update_attributes</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:user</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC43'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">format</span><span class="o">.</span><span class="n">html</span> <span class="p">{</span> <span class="n">redirect_to</span><span class="p">(</span><span class="vi">@user</span><span class="p">,</span> <span class="ss">:notice</span> <span class="o">=&gt;</span> <span class="s1">&#39;User was successfully updated.&#39;</span><span class="p">)</span> <span class="p">}</span></div><div class='line' id='LC44'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">else</span></div><div class='line' id='LC45'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">format</span><span class="o">.</span><span class="n">html</span> <span class="p">{</span> <span class="n">render</span> <span class="ss">:action</span> <span class="o">=&gt;</span> <span class="s2">&quot;edit&quot;</span> <span class="p">}</span></div><div class='line' id='LC46'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC47'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC48'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC49'>&nbsp;&nbsp;</div><div class='line' id='LC50'>&nbsp;&nbsp;<span class="kp">private</span></div><div class='line' id='LC51'>&nbsp;&nbsp;</div><div class='line' id='LC52'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">is_user</span></div><div class='line' id='LC53'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="no">User</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:id</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC54'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@user</span> <span class="o">=</span> <span class="no">User</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:id</span><span class="o">]</span><span class="p">);</span></div><div class='line' id='LC55'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="o">!</span><span class="n">current_user</span> <span class="o">||</span> <span class="n">current_user</span><span class="o">.</span><span class="n">id</span> <span class="o">!=</span> <span class="vi">@user</span><span class="o">.</span><span class="n">id</span></div><div class='line' id='LC56'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">redirect_to</span><span class="p">(</span><span class="n">homepage_url</span><span class="p">,</span> <span class="ss">:notice</span> <span class="o">=&gt;</span><span class="s2">&quot;You do not have access to that page&quot;</span><span class="p">)</span></div><div class='line' id='LC57'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC58'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">else</span></div><div class='line' id='LC59'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">redirect_to</span><span class="p">(</span><span class="n">homepage_url</span><span class="p">,</span> <span class="ss">:notice</span> <span class="o">=&gt;</span><span class="s2">&quot;You do not have access to that page&quot;</span><span class="p">)</span></div><div class='line' id='LC60'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC61'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC62'><br/></div><div class='line' id='LC63'><span class="k">end</span></div><div class='line' id='LC64'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/635885/b6d4c341309a1504083da98914137d9a20b469c6/user_controller.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/635885#file_user_controller.rb" style="float:right;margin-right:10px;color:#666">user_controller.rb</a>
            <a href="https://gist.github.com/635885">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>In this controller we added a function is_user.  This function determines if the user is logged in and they are the correct user to be viewing specific pages.  We also changed redirect urls to the site homepage and removed a lot of unused code. Now lets update our User View:  We&#8217;ll have to change the links on all the pages as well as display less confidential information on the Profile page.</p>
<div id="gist-635896" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nt">&lt;h1</span> <span class="na">id=</span><span class="s">&quot;page_title&quot;</span><span class="nt">&gt;</span>Edit Your Profile<span class="nt">&lt;/h1&gt;</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="cp">&lt;%=</span> <span class="n">render</span> <span class="s1">&#39;form&#39;</span> <span class="cp">%&gt;</span></div><div class='line' id='LC4'><br/></div><div class='line' id='LC5'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s1">&#39;Show&#39;</span><span class="p">,</span> <span class="vi">@user</span> <span class="cp">%&gt;</span> |</div><div class='line' id='LC6'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s1">&#39;Back&#39;</span><span class="p">,</span> <span class="n">homepage_url</span> <span class="cp">%&gt;</span></div><div class='line' id='LC7'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/635896/9138ea430f6a7424caed5a2b839ae6912ea5b910/edit.html.erb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/635896#file_edit.html.erb" style="float:right;margin-right:10px;color:#666">edit.html.erb</a>
            <a href="https://gist.github.com/635896">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nt">&lt;h1</span> <span class="na">id=</span><span class="s">&quot;page_title&quot;</span><span class="nt">&gt;</span>Registration<span class="nt">&lt;/h1&gt;</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="cp">&lt;%=</span> <span class="n">render</span> <span class="s1">&#39;form&#39;</span> <span class="cp">%&gt;</span></div><div class='line' id='LC4'><br/></div><div class='line' id='LC5'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s1">&#39;Back&#39;</span><span class="p">,</span> <span class="n">homepage_url</span> <span class="cp">%&gt;</span></div><div class='line' id='LC6'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/635896/24058e116b7e5b3387d4ba22ed30872d90a2d129/new.html.erb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/635896#file_new.html.erb" style="float:right;margin-right:10px;color:#666">new.html.erb</a>
            <a href="https://gist.github.com/635896">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nt">&lt;h1</span> <span class="na">id=</span><span class="s">&quot;page_title&quot;</span><span class="nt">&gt;</span><span class="cp">&lt;%=</span> <span class="vi">@user</span><span class="o">.</span><span class="n">username</span> <span class="cp">%&gt;</span>&#39;s Profile<span class="nt">&lt;/h1&gt;</span></div><div class='line' id='LC2'><span class="nt">&lt;p</span> <span class="na">id=</span><span class="s">&quot;notice&quot;</span><span class="nt">&gt;</span><span class="cp">&lt;%=</span> <span class="n">notice</span> <span class="cp">%&gt;</span><span class="nt">&lt;/p&gt;</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'><span class="nt">&lt;p&gt;</span></div><div class='line' id='LC5'>&nbsp;&nbsp;<span class="nt">&lt;b&gt;</span>Username:<span class="nt">&lt;/b&gt;</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="vi">@user</span><span class="o">.</span><span class="n">username</span> <span class="cp">%&gt;</span></div><div class='line' id='LC7'><span class="nt">&lt;/p&gt;</span></div><div class='line' id='LC8'><br/></div><div class='line' id='LC9'><span class="nt">&lt;p&gt;</span></div><div class='line' id='LC10'>&nbsp;&nbsp;<span class="nt">&lt;b&gt;</span>Email:<span class="nt">&lt;/b&gt;</span></div><div class='line' id='LC11'>&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="vi">@user</span><span class="o">.</span><span class="n">email</span> <span class="cp">%&gt;</span></div><div class='line' id='LC12'><span class="nt">&lt;/p&gt;</span></div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'><br/></div><div class='line' id='LC15'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s1">&#39;Rails Boards&#39;</span><span class="p">,</span> <span class="n">homepage_url</span> <span class="cp">%&gt;</span></div><div class='line' id='LC16'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/635896/35f342d8f3c93812cf4e9eec4b6d04702bfc995e/show.html.erb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/635896#file_show.html.erb" style="float:right;margin-right:10px;color:#666">show.html.erb</a>
            <a href="https://gist.github.com/635896">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Now we just have to fix the Login view and the login/logout controller.  These files need to have some cosmetic changes and fix issues with redirects open up <em>app/views/user_sessions/new.html.erb</em> and <em>app/controllers/user_sessions_controller.rb</em> and edit them to look like the following:</p>
<div id="gist-635902" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nt">&lt;h1</span> <span class="na">id=</span><span class="s">&quot;page_title&quot;</span><span class="nt">&gt;</span>Login<span class="nt">&lt;/h1&gt;</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'><span class="cp">&lt;%=</span> <span class="n">render</span> <span class="s1">&#39;form&#39;</span> <span class="cp">%&gt;</span></div><div class='line' id='LC4'><br/></div><div class='line' id='LC5'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s1">&#39;Back&#39;</span><span class="p">,</span> <span class="n">homepage_url</span> <span class="cp">%&gt;</span></div><div class='line' id='LC6'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/635902/db9873550279d634b98019276d597a3c057dba27/new.html.erb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/635902#file_new.html.erb" style="float:right;margin-right:10px;color:#666">new.html.erb</a>
            <a href="https://gist.github.com/635902">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="k">class</span> <span class="nc">UserSessionsController</span> <span class="o">&lt;</span> <span class="no">ApplicationController</span></div><div class='line' id='LC2'><br/></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="c1"># GET /user_sessions/new</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">new</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@user_session</span> <span class="o">=</span> <span class="no">UserSession</span><span class="o">.</span><span class="n">new</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC7'><br/></div><div class='line' id='LC8'>&nbsp;&nbsp;<span class="c1"># POST /user_sessions</span></div><div class='line' id='LC9'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">create</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@user_session</span> <span class="o">=</span> <span class="no">UserSession</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:user_session</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC11'><br/></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="vi">@user_session</span><span class="o">.</span><span class="n">save</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">redirect_to</span><span class="p">(</span><span class="n">homepage_url</span><span class="p">,</span> <span class="ss">:notice</span> <span class="o">=&gt;</span> <span class="s1">&#39;Login Successful&#39;</span><span class="p">)</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">else</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">render</span> <span class="ss">:action</span> <span class="o">=&gt;</span> <span class="s2">&quot;new&quot;</span> </div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC17'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC18'><br/></div><div class='line' id='LC19'>&nbsp;&nbsp;<span class="c1"># DELETE /user_sessions/1</span></div><div class='line' id='LC20'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">destroy</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@user_session</span> <span class="o">=</span> <span class="no">UserSession</span><span class="o">.</span><span class="n">find</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@user_session</span><span class="o">.</span><span class="n">destroy</span></div><div class='line' id='LC23'><br/></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">redirect_to</span><span class="p">(</span><span class="n">homepage_url</span><span class="p">,</span> <span class="ss">:notice</span> <span class="o">=&gt;</span> <span class="s1">&#39;Goodbye!&#39;</span><span class="p">)</span></div><div class='line' id='LC25'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC26'><span class="k">end</span></div><div class='line' id='LC27'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/635902/67323ed293077a5aa888a40a2cde4275cf2e8070/user_session_controller.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/635902#file_user_session_controller.rb" style="float:right;margin-right:10px;color:#666">user_session_controller.rb</a>
            <a href="https://gist.github.com/635902">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Now we just changed all the automatic form rerouting to point to our default homepage, added some basic styling, and changed the links in the site to point to more logical places. Lets create some content</p>
<h3>Creating a New Post</h3>
<p>There are four parts to our new posts: author, board, title, body.  Author will be determined by the user_session, board will be determine through the URL, what our form needs to get from the user is title and body.  We must modify the Conversation controller to create a Comment object which we can use in the view.<br />
Open up app/controllers/conversation.rb and modify create and new functions to look like this:</p>
<div id="gist-633853" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="c1"># GET /conversations/new</span></div><div class='line' id='LC2'><span class="k">def</span> <span class="nf">new</span></div><div class='line' id='LC3'>&nbsp;&nbsp;<span class="vi">@conversation</span> <span class="o">=</span> <span class="no">Conversation</span><span class="o">.</span><span class="n">new</span></div><div class='line' id='LC4'>&nbsp;&nbsp;<span class="vi">@comment</span> <span class="o">=</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">comments</span><span class="o">.</span><span class="n">build</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="n">respond_to</span> <span class="k">do</span> <span class="o">|</span><span class="nb">format</span><span class="o">|</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">format</span><span class="o">.</span><span class="n">html</span> <span class="c1"># new.html.erb</span></div><div class='line' id='LC8'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC9'><span class="k">end</span></div><div class='line' id='LC10'><br/></div><div class='line' id='LC11'><span class="c1"># POST /conversations</span></div><div class='line' id='LC12'><span class="k">def</span> <span class="nf">create</span></div><div class='line' id='LC13'>&nbsp;&nbsp;<span class="vi">@conversation</span> <span class="o">=</span> <span class="no">Conversation</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:conversation</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC14'>&nbsp;&nbsp;<span class="vi">@comment</span> <span class="o">=</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">comments</span><span class="o">.</span><span class="n">build</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:comment</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC15'>&nbsp;&nbsp;<span class="vi">@conversation</span><span class="o">.</span><span class="n">user_id</span>  <span class="o">=</span> <span class="vi">@comment</span><span class="o">.</span><span class="n">user_id</span> <span class="o">=</span> <span class="n">current_user</span><span class="o">.</span><span class="n">id</span></div><div class='line' id='LC16'>&nbsp;&nbsp;<span class="vi">@conversation</span><span class="o">.</span><span class="n">board</span> <span class="o">=</span> <span class="vi">@board</span></div><div class='line' id='LC17'>&nbsp;&nbsp;</div><div class='line' id='LC18'>&nbsp;&nbsp;<span class="n">respond_to</span> <span class="k">do</span> <span class="o">|</span><span class="nb">format</span><span class="o">|</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="n">current_user</span> <span class="o">&amp;&amp;</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">save</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">format</span><span class="o">.</span><span class="n">html</span> <span class="p">{</span> <span class="n">redirect_to</span><span class="p">(</span><span class="n">board_path</span><span class="p">(</span><span class="vi">@board</span><span class="p">),</span> <span class="ss">:notice</span> <span class="o">=&gt;</span> <span class="s1">&#39;Your Post was created&#39;</span><span class="p">)</span> <span class="p">}</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">else</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">format</span><span class="o">.</span><span class="n">html</span> <span class="p">{</span> <span class="n">render</span> <span class="ss">:action</span> <span class="o">=&gt;</span> <span class="s2">&quot;new&quot;</span> <span class="p">}</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC24'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC25'><span class="k">end</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/633853/ab2810ce5a826069e8d1cf4e130b4f82a7804199/conversation.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/633853#file_conversation.rb" style="float:right;margin-right:10px;color:#666">conversation.rb</a>
            <a href="https://gist.github.com/633853">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>The build function was automatically created when we used <em>has_many :comments</em> in the model, it creates an unsaved object using default values.  In the create function we&#8217;ve added the board and author variable assignment, we also check to see if the user is logged in before we save.</p>
<p> <code>if current_user &amp;&amp; @conversation.save</code></p>
<p>We create @comment in both places for simplicity.  Both of these function use the same view, create if there is an error and new by default, thus we need the same variables in scope.  In the create function we pass in <em>params[:comment]</em> to build, this will build a Comment object with any data passed in the comment parameter.</p>
<p>Now lets setup our views, change <em>app/views/conversations/index.html.erb</em>, <em>app/views/conversations/_form.html.erb</em> to look like this:
<div id="gist-633849" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;%=</span> <span class="n">form_for</span><span class="p">(</span><span class="vi">@conversation</span><span class="p">,</span> <span class="ss">:url</span> <span class="o">=&gt;</span> <span class="n">board_conversations_path</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">f</span><span class="o">|</span> <span class="cp">%&gt;</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="k">if</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">errors</span><span class="o">.</span><span class="n">any?</span> <span class="cp">%&gt;</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">&quot;error_explanation&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;h2&gt;</span><span class="cp">&lt;%=</span> <span class="n">pluralize</span><span class="p">(</span><span class="vi">@conversation</span><span class="o">.</span><span class="n">errors</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="s2">&quot;error&quot;</span><span class="p">)</span> <span class="cp">%&gt;</span> prohibited this conversation from being saved:<span class="nt">&lt;/h2&gt;</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;ul&gt;</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">errors</span><span class="o">.</span><span class="n">full_messages</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">msg</span><span class="o">|</span> <span class="cp">%&gt;</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;li&gt;</span><span class="cp">&lt;%=</span> <span class="n">msg</span> <span class="cp">%&gt;</span><span class="nt">&lt;/li&gt;</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/ul&gt;</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/div&gt;</span></div><div class='line' id='LC12'>&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span></div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'>&nbsp;&nbsp;<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;field&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">f</span><span class="o">.</span><span class="n">label</span> <span class="ss">:title</span> <span class="cp">%&gt;</span><span class="nt">&lt;br</span> <span class="nt">/&gt;</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">f</span><span class="o">.</span><span class="n">text_field</span> <span class="ss">:title</span> <span class="cp">%&gt;</span></div><div class='line' id='LC17'>&nbsp;&nbsp;<span class="nt">&lt;/div&gt;</span></div><div class='line' id='LC18'><br/></div><div class='line' id='LC19'>&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">fields_for</span><span class="p">(</span><span class="vi">@comment</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">cf</span><span class="o">|</span><span class="cp">%&gt;</span></div><div class='line' id='LC20'>&nbsp;&nbsp;<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;field&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">cf</span><span class="o">.</span><span class="n">label</span> <span class="ss">:body</span> <span class="cp">%&gt;</span><span class="nt">&lt;br</span> <span class="nt">/&gt;</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">cf</span><span class="o">.</span><span class="n">text_area</span><span class="p">(</span><span class="ss">:body</span><span class="p">,</span> <span class="ss">:size</span> <span class="o">=&gt;</span> <span class="s2">&quot;60x10&quot;</span><span class="p">)</span><span class="cp">%&gt;</span></div><div class='line' id='LC23'>&nbsp;&nbsp;<span class="nt">&lt;/div&gt;</span></div><div class='line' id='LC24'>&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span></div><div class='line' id='LC25'>&nbsp;&nbsp;</div><div class='line' id='LC26'><br/></div><div class='line' id='LC27'>&nbsp;&nbsp;<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;actions&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">f</span><span class="o">.</span><span class="n">submit</span> <span class="ss">:as</span> <span class="o">=&gt;</span> <span class="s2">&quot;Create Post&quot;</span><span class="cp">%&gt;</span></div><div class='line' id='LC29'>&nbsp;&nbsp;<span class="nt">&lt;/div&gt;</span></div><div class='line' id='LC30'><span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span></div><div class='line' id='LC31'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/633849/dd73acda32570a9a7b7405fb531387e654829b3f/_form.html.erb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/633849#file__form.html.erb" style="float:right;margin-right:10px;color:#666">_form.html.erb</a>
            <a href="https://gist.github.com/633849">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>&lt;h1 id=&quot;page_title&quot;&gt;New conversation&lt;/h1&gt;</div><div class='line' id='LC2'>&lt;%= link_to @board.title, @board %&gt;</div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'>&lt;%= render &#39;form&#39; %&gt;</div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'>&lt;%= link_to @board.title, @board %&gt;</div><div class='line' id='LC7'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/633849/205ffc1f68925cbcd510a9be2ea99b9cfd41b93a/new.html.ner" style="float:right;">view raw</a>
            <a href="https://gist.github.com/633849#file_new.html.ner" style="float:right;margin-right:10px;color:#666">new.html.ner</a>
            <a href="https://gist.github.com/633849">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>The changes to new.html.erb are fairy straight forward. We added an id to the h1 tag, and changed the link to display the name of the current table and link to the current table.  We modified_form.html.erb pretty heavily, we removed alot of the input fields that will be assigned in the controller.  We also modified the error printing at the top to include any errors from @comment.  fields_for works like form_for but does not create a new form tag.  This allows us to create fields that are related to other objects.</p>
<p>Lets create our first post.  When you&#8217;re done it should look something like this:</p>
<p>[img new_post.jpg]</p>
<h3>Viewing Our Post</h3>
<p>You may be wondering where your posts are?  Clearly they&#8217;re in the database but they&#8217;re not showing up in our view.  Lets fix that, open up <em>app/views/boards/show.html.erb</em></p>
<div id="gist-633784" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nt">&lt;h1</span> <span class="na">id=</span><span class="s">&quot;page_title&quot;</span><span class="nt">&gt;</span><span class="cp">&lt;%=</span> <span class="vi">@board</span><span class="o">.</span><span class="n">title</span> <span class="cp">%&gt;</span><span class="nt">&lt;/h1&gt;</span></div><div class='line' id='LC2'><span class="nt">&lt;p</span> <span class="na">id=</span><span class="s">&quot;notice&quot;</span><span class="nt">&gt;</span><span class="cp">&lt;%=</span> <span class="n">notice</span> <span class="cp">%&gt;</span><span class="nt">&lt;/p&gt;</span></div><div class='line' id='LC3'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s1">&#39;Rails Boards&#39;</span><span class="p">,</span> <span class="n">boards_path</span> <span class="cp">%&gt;</span> <span class="ni">&amp;gt;</span> <span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="vi">@board</span><span class="o">.</span><span class="n">title</span><span class="p">,</span> <span class="vi">@board</span> <span class="cp">%&gt;</span> <span class="nt">&lt;br</span> <span class="nt">/&gt;</span></div><div class='line' id='LC4'><br/></div><div class='line' id='LC5'><span class="nt">&lt;table&gt;</span></div><div class='line' id='LC6'>&nbsp;&nbsp;<span class="nt">&lt;tr&gt;</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;th&gt;</span>Post / Author<span class="nt">&lt;/th&gt;</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;th&gt;</span>Last Reply<span class="nt">&lt;/th&gt;</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;th&gt;</span>Number of Replies<span class="nt">&lt;/th&gt;</span></div><div class='line' id='LC10'>&nbsp;&nbsp;<span class="nt">&lt;/tr&gt;</span></div><div class='line' id='LC11'><span class="cp">&lt;%</span> <span class="vi">@board</span><span class="o">.</span><span class="n">conversations</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">conversation</span><span class="o">|</span> <span class="cp">%&gt;</span></div><div class='line' id='LC12'>&nbsp;&nbsp;<span class="nt">&lt;tr&gt;</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;td&gt;</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="n">conversation</span><span class="o">.</span><span class="n">title</span><span class="p">,</span> <span class="n">board_conversation_path</span><span class="p">(</span><span class="ss">:board_id</span> <span class="o">=&gt;</span> <span class="vi">@board</span><span class="p">,</span> <span class="ss">:id</span> <span class="o">=&gt;</span> <span class="n">conversation</span><span class="p">)</span> <span class="cp">%&gt;</span><span class="nt">&lt;br</span> <span class="nt">/&gt;</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">conversation</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">username</span> <span class="cp">%&gt;</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/td&gt;</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;td&gt;</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">conversation</span><span class="o">.</span><span class="n">comments</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="ss">:last</span><span class="p">)</span><span class="o">.</span><span class="n">created_at</span> <span class="cp">%&gt;</span><span class="nt">&lt;br</span> <span class="nt">/&gt;</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by <span class="cp">&lt;%=</span> <span class="n">conversation</span><span class="o">.</span><span class="n">comments</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="ss">:last</span><span class="p">)</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">username</span> <span class="cp">%&gt;</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/td&gt;</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;td&gt;</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">conversation</span><span class="o">.</span><span class="n">comments</span><span class="o">.</span><span class="n">count</span> <span class="o">-</span> <span class="mi">1</span><span class="cp">%&gt;</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/td&gt;</span></div><div class='line' id='LC24'>&nbsp;&nbsp;<span class="nt">&lt;/tr&gt;</span></div><div class='line' id='LC25'><span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span></div><div class='line' id='LC26'><span class="nt">&lt;/table&gt;</span></div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC28'><br/></div><div class='line' id='LC29'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s1">&#39;Post New Message&#39;</span><span class="p">,</span> <span class="n">new_board_conversation_url</span><span class="p">(</span><span class="vi">@board</span><span class="p">)</span> <span class="cp">%&gt;</span></div><div class='line' id='LC30'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/633784/8045fae3e1441e4df6f84d7a5ed793fe2d4018db/shows.html.erb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/633784#file_shows.html.erb" style="float:right;margin-right:10px;color:#666">shows.html.erb</a>
            <a href="https://gist.github.com/633784">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>We display all the conversations in that board along with some basic meta data.  Most of this code is rather straight forward, the link to uses one of the routes that can be easily found using <em>$ rake routes </em>.  We use the <a href="http://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-find">find function</a> which was also provided when we used <em>has_many</em>.  We subtract one for the number of replies so that we do not count the post it self.  But all in all this view is as straight forward as they come.</p>
<p>Now lets work on the message view itself.  Open up <em>app/views/conversation/show.html.erb</em> and edit to look like this:</p>
<div id="gist-633803" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">board</span><span class="o">.</span><span class="n">title</span><span class="p">,</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">board</span><span class="cp">%&gt;</span></div><div class='line' id='LC2'><span class="nt">&lt;p</span> <span class="na">id=</span><span class="s">&quot;notice&quot;</span><span class="nt">&gt;</span><span class="cp">&lt;%=</span> <span class="n">notice</span> <span class="cp">%&gt;</span><span class="nt">&lt;/p&gt;</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'><br/></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'><span class="nt">&lt;table&gt;</span></div><div class='line' id='LC7'>&nbsp;&nbsp;<span class="nt">&lt;tr&gt;</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;th</span> <span class="na">colspan=</span><span class="s">&quot;2&quot;</span><span class="nt">&gt;</span><span class="cp">&lt;%=</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">title</span> <span class="cp">%&gt;</span><span class="nt">&lt;/th&gt;</span></div><div class='line' id='LC9'>&nbsp;&nbsp;<span class="nt">&lt;/tr&gt;</span></div><div class='line' id='LC10'>&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">comments</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">comment</span><span class="o">|</span> <span class="cp">%&gt;</span></div><div class='line' id='LC11'>&nbsp;&nbsp;<span class="nt">&lt;tr&gt;</span></div><div class='line' id='LC12'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;td</span> <span class="na">style=</span><span class="s">&quot;width:25%;&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="n">comment</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="n">comment</span><span class="o">.</span><span class="n">user</span> <span class="cp">%&gt;</span> <span class="nt">&lt;br</span> <span class="nt">/&gt;</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Posted At <span class="nt">&lt;br</span> <span class="nt">/&gt;</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">comment</span><span class="o">.</span><span class="n">created_at</span><span class="cp">%&gt;</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/td&gt;</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;td&gt;</span></div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;p&gt;</span><span class="cp">&lt;%=</span><span class="n">comment</span><span class="o">.</span><span class="n">body</span><span class="cp">%&gt;</span><span class="nt">&lt;/p&gt;</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/td&gt;</span></div><div class='line' id='LC20'>&nbsp;&nbsp;<span class="nt">&lt;/tr&gt;</span></div><div class='line' id='LC21'>&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span></div><div class='line' id='LC22'><span class="nt">&lt;/table&gt;</span></div><div class='line' id='LC23'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="s1">&#39;Reply&#39;</span><span class="p">,</span> <span class="n">reply_board_conversation_url</span><span class="p">(</span><span class="ss">:board_id</span><span class="o">=&gt;</span><span class="vi">@board</span><span class="p">,</span> <span class="ss">:id</span><span class="o">=&gt;</span><span class="vi">@conversation</span><span class="p">)</span><span class="cp">%&gt;</span> |</div><div class='line' id='LC24'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">board</span><span class="o">.</span><span class="n">title</span><span class="p">,</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">board</span><span class="cp">%&gt;</span></div><div class='line' id='LC25'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/633803/1f2d85a1dcd4f88bbeda15c4b4a0329110c73ce1/show.html.erb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/633803#file_show.html.erb" style="float:right;margin-right:10px;color:#666">show.html.erb</a>
            <a href="https://gist.github.com/633803">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Once again nothing to exciting happening here, the more astute of you may have realized we created a url function that we don&#8217;t currently have mapped.  Lets create that route, add</p>
<p><code><br />
get '/boards/:board_id/conversations/:id/reply' =&gt; "conversations#reply", :as =&gt; :reply_board_conversation<br />
post  '/boards/:board_id/conversations/:id/reply' =&gt; "conversations#save_reply", :as =&gt; :reply_board_conversation<br />
</code></p>
<p>This will create two different url matches, one for GET requests and one for POST, one when the page is called and one when the form is submitted.<br />
Lets got and create the reply and save_reply functions in the conversation controller, they should look fairly similar to the new and create functions, or like these:</p>
<div id="gist-633839" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'>&nbsp;&nbsp;<span class="c1"># GET /conversations/reply</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">reply</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@conversation</span> <span class="o">=</span> <span class="no">Conversation</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:id</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@comment</span> <span class="o">=</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">comments</span><span class="o">.</span><span class="n">build</span></div><div class='line' id='LC5'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">respond_to</span> <span class="k">do</span> <span class="o">|</span><span class="nb">format</span><span class="o">|</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">format</span><span class="o">.</span><span class="n">html</span> <span class="c1">#reply.html.erb</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC9'>&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC10'>&nbsp;&nbsp;</div><div class='line' id='LC11'>&nbsp;&nbsp;<span class="c1"># POST /conversations/reply</span></div><div class='line' id='LC12'>&nbsp;&nbsp;<span class="k">def</span> <span class="nf">save_reply</span></div><div class='line' id='LC13'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="o">!</span><span class="n">current_user</span></div><div class='line' id='LC14'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">redirect_to</span><span class="p">(</span><span class="ss">:login</span><span class="p">,</span> <span class="ss">:notice</span> <span class="o">=&gt;</span><span class="s2">&quot;Please login before posting&quot;</span><span class="p">)</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">return</span> <span class="mi">1</span><span class="p">;</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC17'>&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC18'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="no">Conversation</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:id</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC19'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@conversation</span> <span class="o">=</span> <span class="no">Conversation</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:id</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC20'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@comment</span> <span class="o">=</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">comments</span><span class="o">.</span><span class="n">build</span><span class="p">(</span><span class="n">params</span><span class="o">[</span><span class="ss">:comment</span><span class="o">]</span><span class="p">)</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="vi">@comment</span><span class="o">.</span><span class="n">user_id</span> <span class="o">=</span> <span class="n">current_user</span><span class="o">.</span><span class="n">id</span></div><div class='line' id='LC22'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">else</span></div><div class='line' id='LC23'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">redirect_to</span><span class="p">(</span><span class="n">boards_path</span><span class="p">,</span> <span class="ss">:notice</span> <span class="o">=&gt;</span><span class="s2">&quot;Please specify a valid board&quot;</span><span class="p">)</span></div><div class='line' id='LC24'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC25'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div><div class='line' id='LC26'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="n">respond_to</span> <span class="k">do</span> <span class="o">|</span><span class="nb">format</span><span class="o">|</span></div><div class='line' id='LC27'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">if</span> <span class="n">current_user</span> <span class="o">&amp;&amp;</span> <span class="vi">@comment</span><span class="o">.</span><span class="n">save</span></div><div class='line' id='LC28'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">format</span><span class="o">.</span><span class="n">html</span> <span class="p">{</span> <span class="n">redirect_to</span><span class="p">(</span><span class="n">board_path</span><span class="p">(</span><span class="vi">@board</span><span class="p">),</span> <span class="ss">:notice</span> <span class="o">=&gt;</span> <span class="s1">&#39;Your reply was posted&#39;</span><span class="p">)</span> <span class="p">}</span></div><div class='line' id='LC29'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">else</span></div><div class='line' id='LC30'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nb">format</span><span class="o">.</span><span class="n">html</span> <span class="p">{</span> <span class="n">render</span> <span class="ss">:action</span> <span class="o">=&gt;</span> <span class="s2">&quot;new&quot;</span> <span class="p">}</span></div><div class='line' id='LC31'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC32'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="k">end</span></div><div class='line' id='LC33'>&nbsp;&nbsp;<span class="k">end</span></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/633839/e7dd96575ec22137704569dd20a3cfa3dedd9163/conversation.rb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/633839#file_conversation.rb" style="float:right;margin-right:10px;color:#666">conversation.rb</a>
            <a href="https://gist.github.com/633839">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>Once again here nothing is too revolutionary.  reply handles the page load.  It creates a @conversation and @comment for use in the view to generate forms.  The @conversation is loaded from the url, as is a @board.  @comment is empty.  save_reply handles POST requests, so form submissions.  It verifies that the user is logged in and that the parent conversation exists.  It then creates the comment from the conversation, assigns the user, and assigns the values passed in from the form.  It saves the data and redirects the user to the board overview with a friendly reminder.</p>
<p>Reply function uses <em>reply.html.erb</em> as it&#8217;s view, since that hasn&#8217;t been created yet lets do that now.  Create another file as well _reply_form.html.erb.  They should look like this:</p>
<div id="gist-633846" class="gist">

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="cp">&lt;%=</span> <span class="n">form_for</span><span class="p">(</span><span class="vi">@comment</span><span class="p">,</span> <span class="ss">:url</span> <span class="o">=&gt;</span> <span class="n">reply_board_conversation_url</span><span class="p">(</span><span class="ss">:board_id</span><span class="o">=&gt;</span><span class="vi">@board</span><span class="p">,</span> <span class="ss">:id</span><span class="o">=&gt;</span><span class="vi">@conversation</span><span class="p">))</span> <span class="k">do</span> <span class="o">|</span><span class="n">f</span><span class="o">|</span> <span class="cp">%&gt;</span></div><div class='line' id='LC2'>&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="k">if</span> <span class="vi">@comment</span><span class="o">.</span><span class="n">errors</span><span class="o">.</span><span class="n">any?</span> <span class="cp">%&gt;</span></div><div class='line' id='LC3'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;div</span> <span class="na">id=</span><span class="s">&quot;error_explanation&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC4'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;h2&gt;</span><span class="cp">&lt;%=</span> <span class="n">pluralize</span><span class="p">(</span><span class="vi">@comment</span><span class="o">.</span><span class="n">errors</span><span class="o">.</span><span class="n">count</span><span class="p">,</span> <span class="s2">&quot;error&quot;</span><span class="p">)</span> <span class="cp">%&gt;</span> prohibited this reply from being saved:<span class="nt">&lt;/h2&gt;</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;ul&gt;</span></div><div class='line' id='LC7'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="vi">@comment</span><span class="o">.</span><span class="n">errors</span><span class="o">.</span><span class="n">full_messages</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">msg</span><span class="o">|</span> <span class="cp">%&gt;</span></div><div class='line' id='LC8'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;li&gt;</span><span class="cp">&lt;%=</span> <span class="n">msg</span> <span class="cp">%&gt;</span><span class="nt">&lt;/li&gt;</span></div><div class='line' id='LC9'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span></div><div class='line' id='LC10'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/ul&gt;</span></div><div class='line' id='LC11'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="nt">&lt;/div&gt;</span></div><div class='line' id='LC12'>&nbsp;&nbsp;<span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span></div><div class='line' id='LC13'><br/></div><div class='line' id='LC14'>&nbsp;&nbsp;<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;field&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC15'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">f</span><span class="o">.</span><span class="n">label</span> <span class="ss">:body</span> <span class="cp">%&gt;</span><span class="nt">&lt;br</span> <span class="nt">/&gt;</span></div><div class='line' id='LC16'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">f</span><span class="o">.</span><span class="n">text_area</span><span class="p">(</span><span class="ss">:body</span><span class="p">,</span> <span class="ss">:size</span> <span class="o">=&gt;</span> <span class="s2">&quot;60x10&quot;</span><span class="p">)</span><span class="cp">%&gt;</span></div><div class='line' id='LC17'>&nbsp;&nbsp;<span class="nt">&lt;/div&gt;</span></div><div class='line' id='LC18'>&nbsp;&nbsp;</div><div class='line' id='LC19'><br/></div><div class='line' id='LC20'>&nbsp;&nbsp;<span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">&quot;actions&quot;</span><span class="nt">&gt;</span></div><div class='line' id='LC21'>&nbsp;&nbsp;&nbsp;&nbsp;<span class="cp">&lt;%=</span> <span class="n">f</span><span class="o">.</span><span class="n">submit</span><span class="p">(</span><span class="ss">:value</span> <span class="o">=&gt;</span> <span class="s2">&quot;Create Reply&quot;</span><span class="p">)</span><span class="cp">%&gt;</span></div><div class='line' id='LC22'>&nbsp;&nbsp;<span class="nt">&lt;/div&gt;</span></div><div class='line' id='LC23'><span class="cp">&lt;%</span> <span class="k">end</span> <span class="cp">%&gt;</span></div><div class='line' id='LC24'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/633846/f13f173673ab84b103c144ac363935a2b17e4d9f/_reply_form.html.erb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/633846#file__reply_form.html.erb" style="float:right;margin-right:10px;color:#666">_reply_form.html.erb</a>
            <a href="https://gist.github.com/633846">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>

        <div class="gist-file">
          <div class="gist-data gist-syntax">
              <div class="highlight"><pre><div class='line' id='LC1'><span class="nt">&lt;h1</span> <span class="na">id=</span><span class="s">&quot;page_title&quot;</span><span class="nt">&gt;</span>Reply To <span class="cp">&lt;%=</span> <span class="vi">@conversation</span><span class="o">.</span><span class="n">title</span> <span class="cp">%&gt;</span><span class="nt">&lt;/h1&gt;</span></div><div class='line' id='LC2'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="vi">@board</span><span class="o">.</span><span class="n">title</span><span class="p">,</span> <span class="vi">@board</span> <span class="cp">%&gt;</span></div><div class='line' id='LC3'><br/></div><div class='line' id='LC4'><span class="cp">&lt;%=</span> <span class="n">render</span> <span class="s1">&#39;reply_form&#39;</span> <span class="cp">%&gt;</span></div><div class='line' id='LC5'><br/></div><div class='line' id='LC6'><span class="cp">&lt;%=</span> <span class="n">link_to</span> <span class="vi">@board</span><span class="o">.</span><span class="n">title</span><span class="p">,</span> <span class="vi">@board</span> <span class="cp">%&gt;</span></div><div class='line' id='LC7'><br/></div></pre></div>
          </div>

          <div class="gist-meta">
            <a href="https://gist.github.com/raw/633846/21d2a49b3a3146df1cc40a2c19b63ed08d14a473/reply.html.erb" style="float:right;">view raw</a>
            <a href="https://gist.github.com/633846#file_reply.html.erb" style="float:right;margin-right:10px;color:#666">reply.html.erb</a>
            <a href="https://gist.github.com/633846">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
          </div>
        </div>
</div>

<p>There is nothing we haven&#8217;t seen before in these files by themselves.  <em>Reply.html.erb</em> includes _reply_form.html.erb you can tell this by the render statement, &#8216;reply_form&#8217; is prepended with &#8216;_&#8217; so you know it&#8217;s not a controller view. <em>_reply_form.html.erb</em> uses the same action as we saw to generate the url to this page, and only has a text area input field.</p>
<p>Feel free to try it now out now.  The complete forum/message board should be working.  If you have any questions feel free to leave a comment or view the working code base on my <a href="http://github.com/baileylo/Rails-Boards">GitHub For Rails boards</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.logansbailey.com/2010/10/19/how-to-build-forums-in-rails-3/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

