<?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>Meta Bates &#187; tutorial</title>
	<atom:link href="http://www.metabates.com/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.metabates.com</link>
	<description>The technical ramblings of Mark Bates.</description>
	<lastBuildDate>Wed, 01 Feb 2012 16:25:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>0.4.6: The Obligatory &#8216;Blog&#8217; Demo &#8211; Take 2</title>
		<link>http://www.metabates.com/2008/04/18/046-the-obligatory-blog-demo-take-2/</link>
		<comments>http://www.metabates.com/2008/04/18/046-the-obligatory-blog-demo-take-2/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 22:12:04 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[active record]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[data mapper]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[mack]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[scaffold]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/?p=60</guid>
		<description><![CDATA[This post has moved to the wiki @&#160;http://wiki.mackframework.com/index.php/Blog%20Tutorial]]></description>
			<content:encoded><![CDATA[<p>This post has moved to the wiki @&nbsp;<a href="http://wiki.mackframework.com/index.php/Blog%20Tutorial" target="_blank">http://wiki.mackframework.com/index.php/Blog%20Tutorial</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/04/18/046-the-obligatory-blog-demo-take-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>0.1.0: The Obligatory &#8216;Blog&#8217; Demo</title>
		<link>http://www.metabates.com/2008/03/04/the-obligatory-blog-demo/</link>
		<comments>http://www.metabates.com/2008/03/04/the-obligatory-blog-demo/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 20:15:46 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[data mapper]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[mack]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[scaffold]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/2008/03/04/the-obligatory-blog-demo/</guid>
		<description><![CDATA[Ok, because every good framework should tell you how to create a blog, why should Mack be any different? Let&#8217;s start off with the basics. Is Mack installed? If not, here&#8217;s how: $ sudo gem install mack Great! Before we move on, make sure that the gem you installed is at LEAST version 0.1.0, otherwise, [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, because every good framework should tell you how to create a blog, why should Mack be any different? Let&#8217;s start off with the basics. Is Mack installed? If not, here&#8217;s how:</p>
<pre>$ sudo gem install mack</pre>
<p>Great! Before we move on, make sure that the gem you installed is at LEAST version 0.1.0, otherwise, you&#8217;re not going to get very far in this tutorial. Now, let&#8217;s move on. Now let&#8217;s generate our kick ass new blog, and since we&#8217;re going to need some sort of database support for our blog, we&#8217;ll configure it to use DataMapper. If you don&#8217;t have DataMapper installed, please head over to <a href="http://datamapper.org" target="_blank">http://datamapper.org</a> to find out how to install it. Mack has support for ActiveRecord as well, but it&#8217;s just easier to get DataMapper going because you don&#8217;t have to deal with migrations.</p>
<pre>$ mack my_kick_ass_blog -o data_mapper
$ cd my_kick_ass_blog</pre>
<p>That should&#8217;ve created a whole bunch of files and folders for your blog. Now let&#8217;s generate some scaffold code for our blog:</p>
<pre>$ rake generate:scaffold name=posts</pre>
<p>That should&#8217;ve created even more files for you. One of those files is app/models/post.rb, let&#8217;s open that up, so we can edit it for DataMapper.</p>
<p>Edit the file so it looks something like this:</p>
<pre>class Post &lt; DataMapper::Base
  property :title, :string
  property :email, :string
  property :body, :text
  property :created_at, :datetime
  property :updated_at, :datetime

  validates_presence_of :title
  validates_presence_of :body
  validates_presence_of :email
end</pre>
<p>Now, I&#8217;m not going to go into detail as to what that&#8217;s doing, that&#8217;s for the guys at DataMapper to explain. Before we move on to the next step, you&#8217;ll probably want to crack open config/database.yml and edit it so it the paths to your database are correct, you&#8217;ll probably also want to go to your database system and make sure that the database name you configured in your config/database.yml is created, otherwise this will be a very short trip. I&#8217;ll wait while you do that. Finished, great! Let&#8217;s move on.</p>
<p>We need to now open a Mack console so we can create the tables needed for our blog.</p>
<pre>$ rake console
$ Post.table.create!
$ exit</pre>
<p>Ok, we should now have a posts table in our new database. Isn&#8217;t life wonderful? We&#8217;re so close to showing the world how wonderful we are as developers.</p>
<p>Now let&#8217;s edit our views, so they look something like this:</p>
<p>app/views/posts/index.html.erb:</p>
<pre>&lt;h1&gt;Listing posts&lt;/h1&gt;

&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Title&lt;/th&gt;
    &lt;th&gt;Body&lt;/th&gt;
    &lt;th&gt;Email&lt;/th&gt;
  &lt;/tr&gt;

&lt;% for post in @posts %&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;%=post.title %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%=post.body %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%=post.email %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= link_to("Show", posts_show_url(:id =&gt; post.id)) %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= link_to("Edit", posts_edit_url(:id =&gt; post.id)) %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= link_to("Delete", posts_delete_url(:id =&gt; post.id), :method =&gt; :delete, :confirm =&gt; "Are you sure?") %&gt;&lt;/td&gt;
  &lt;/tr&gt;
&lt;% end %&gt;
&lt;/table&gt;

&lt;br /&gt;

&lt;%= link_to("New Post", posts_new_url) %&gt;</pre>
<p>app/views/posts/edit.html.erb:</p>
<pre>&lt;h1&gt;Edit post&lt;/h1&gt;

&lt;%= error_messages_for :post %&gt;

&lt;form action="&lt;%= posts_update_url(:id =&gt; @post.id) %&gt;" class="edit_post" id="edit_post" method="post"&gt;
  &lt;input type="hidden" name="_method" value="put"&gt;
  &lt;p&gt;
    &lt;b&gt;Title&lt;/b&gt;&lt;br /&gt;
    &lt;input id="post_title" name="post[title]" size="30" type="text" value="&lt;%= @post.title %&gt;" /&gt;
  &lt;/p&gt;

  &lt;p&gt;
    &lt;b&gt;Body&lt;/b&gt;&lt;br /&gt;
    &lt;textarea id="post_body" name="post[body]"&gt;&lt;%= @post.body %&gt;&lt;/textarea&gt;
  &lt;/p&gt;

  &lt;p&gt;
    &lt;b&gt;Email&lt;/b&gt;&lt;br /&gt;
    &lt;input id="post_email" name="post[email]" size="30" type="text" value="&lt;%= @post.email %&gt;" /&gt;
  &lt;/p&gt;

  &lt;p&gt;
    &lt;input id="post_submit" name="commit" type="submit" value="Create" /&gt;
  &lt;/p&gt;
&lt;/form&gt;

&lt;%= link_to("Back", posts_index_url) %&gt;</pre>
<p>app/views/posts/show.html.erb:</p>
<pre>&lt;p&gt;
  &lt;b&gt;Title:&lt;/b&gt;
  &lt;%= @post.title %&gt;
&lt;/p&gt;

&lt;p&gt;
  &lt;b&gt;Body:&lt;/b&gt;
  &lt;%= @post.body %&gt;
&lt;/p&gt;

&lt;p&gt;
  &lt;b&gt;Email:&lt;/b&gt;
  &lt;%= @post.email %&gt;
&lt;/p&gt;

&lt;p&gt;
  &lt;b&gt;Created at:&lt;/b&gt;
  &lt;%= @post.created_at %&gt;
&lt;/p&gt;

&lt;p&gt;
  &lt;b&gt;Updated at:&lt;/b&gt;
  &lt;%= @post.updated_at %&gt;
&lt;/p&gt;

&lt;%= link_to("Edit", posts_edit_url(:id =&gt; @post.id)) %&gt; |
&lt;%= link_to("Back", posts_index_url) %&gt;</pre>
<p>app/views/posts/new.html.erb:</p>
<pre>&lt;h1&gt;New post&lt;/h1&gt;

&lt;%= error_messages_for :post %&gt;

&lt;form action="&lt;%= posts_create_url %&gt;" class="new_post" id="new_post" method="post"&gt;
  &lt;p&gt;
    &lt;b&gt;Title&lt;/b&gt;&lt;br /&gt;
    &lt;input id="post_title" name="post[title]" size="30" type="text" value="&lt;%= @post.title %&gt;" /&gt;
  &lt;/p&gt;

  &lt;p&gt;
    &lt;b&gt;Body&lt;/b&gt;&lt;br /&gt;
    &lt;textarea id="post_body" name="post[body]"&gt;&lt;%= @post.body %&gt;&lt;/textarea&gt;
  &lt;/p&gt;

  &lt;p&gt;
    &lt;b&gt;Email&lt;/b&gt;&lt;br /&gt;
    &lt;input id="post_email" name="post[email]" size="30" type="text" value="&lt;%= @post.email %&gt;" /&gt;
  &lt;/p&gt;

  &lt;p&gt;
    &lt;input id="post_submit" name="commit" type="submit" value="Create" /&gt;
  &lt;/p&gt;
&lt;/form&gt;

&lt;%= link_to("Back", posts_index_url) %&gt;</pre>
<p>Ok, so now we&#8217;ve created our forms, and setup our index page. Let&#8217;s actually go to the site and see it all works!</p>
<p>First we need to start the server:</p>
<p>$ rake server</p>
<p>Now let&#8217;s head on over to http://localhost:3000/posts and see what we&#8217;ve got. You should see a page that looks something like this:</p>
<p><img src="http://www.mackframework.com/wp-content/uploads/2008/03/12.png" alt="Blog Demo 1" /></p>
<p>Now let&#8217;s click on that &#8216;New Post&#8217; link and fill out the form:</p>
<p><img src="http://www.mackframework.com/wp-content/uploads/2008/03/21.png" alt="Blog Demo 2" /></p>
<p>Now, let&#8217;s hit that wonderful &#8216;Create&#8217; button and see what happens!</p>
<p><img src="http://www.mackframework.com/wp-content/uploads/2008/03/31.png" alt="Blog Demo 3" /></p>
<p>Congrats! You just created your first blog post! Now let&#8217;s head back to http://localhost:3000/posts and see what we&#8217;ve got.</p>
<p><img src="http://www.mackframework.com/wp-content/uploads/2008/03/41.png" alt="Blog Demo 4" /></p>
<p>Wonderful! Now all that&#8217;s left to do is to set our home page to our posts index page. Let&#8217;s open up our config/routes.rb and edit the following line:</p>
<pre>r.home_page "/", :controller =&gt; :default, :action =&gt; :index</pre>
<p>so that it&#8217;s now:</p>
<pre>r.home_page "/", :controller =&gt; :posts, :action =&gt; :index</pre>
<p>Now all you have to do is to restart your server and Bob&#8217;s your uncle when you hit http://localhost:3000 again you should your fantastic posts index page.</p>
<p>This concludes our brief introductory tutorial on getting going on Mack. Obviously Mack does a lot more, and I highly encourage you to read the <a href="http://api.mackframework.com">RDoc</a> to find out more about what it can do.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/03/04/the-obligatory-blog-demo/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.355 seconds -->

