<?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; demo</title>
	<atom:link href="http://www.metabates.com/tag/demo/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.metabates.com</link>
	<description>The technical ramblings of Mark Bates.</description>
	<lastBuildDate>Sun, 15 Aug 2010 12:49:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>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.3.0: Adding RSS/xml feeds to our Blog demo</title>
		<link>http://www.metabates.com/2008/03/19/adding-rssxml-feeds-to-our-blog-demo/</link>
		<comments>http://www.metabates.com/2008/03/19/adding-rssxml-feeds-to-our-blog-demo/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 20:42:49 +0000</pubDate>
		<dc:creator>Mark Bates</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[builder]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[mack]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.mackframework.com/2008/03/19/adding-rssxml-feeds-to-our-blog-demo/</guid>
		<description><![CDATA[Ok, as you remember a while back we created a simple blog using mack, http://www.mackframework.com/2008/03/04/the-obligatory-blog-demo/. Well now it&#8217;s time to add the all important RSS/xml feed to it. Mack 0.3.0 introduces xml rendering support natively, so this shouldn&#8217;t be so hard. First things first, let&#8217;s fire up the app, shall we: $ rake server Now [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, as you remember a while back we created a simple blog using mack, <a href="http://www.mackframework.com/2008/03/04/the-obligatory-blog-demo/" target="_blank">http://www.mackframework.com/2008/03/04/the-obligatory-blog-demo/</a>. Well now it&#8217;s time to add the all important RSS/xml feed to it.</p>
<p>Mack 0.3.0 introduces xml rendering support natively, so this shouldn&#8217;t be so hard. First things first, let&#8217;s fire up the app, shall we:</p>
<pre>$ rake server</pre>
<p>Now let&#8217;s head over to http://localhost:3000/posts. We should see our beautiful posts index page. Now let&#8217;s try to go to http://localhost:3000/posts.xml you should see something that looks like this:</p>
<p><img src="http://www.mackframework.com/wp-content/uploads/2008/03/xml1.png" alt="XML blog demo 1" width="450" /></p>
<p>Clearly, that&#8217;s not what we want, is it? I didn&#8217;t think so. The error is telling us that it&#8217;s looking for a file called index.xml.erb in the app/views/posts directory of our blog project. Obviously that file doesn&#8217;t exist.</p>
<p>Let&#8217;s take a second and talk about <em>why</em> Mack was looking for index.xml.erb. We haven&#8217;t changed anything in our controller. Our index method still looks something like this:</p>
<pre>def index
  @posts = Post.find(:all)
end</pre>
<p>No where in there does it mention xml. The only place xml is mentioned is on the the url itself, remember? We looked for /posts.xml. By adding .xml you&#8217;re telling Mack that you want to render, well&#8230; xml. So it goes looking for that. That&#8217;s also new in 0.3.0. The default is html, but if you append a format (.js, .xml, etc&#8230;), it will go looking for app/views/&lt;controller_name&gt;/&lt;action_name&gt;.&lt;format&gt;.erb and render it.</p>
<p>Ok, now that we understand why we&#8217;re looking for an xml file, let&#8217;s fire up our trusty text editor and create a new file called: app/views/posts/index.xml.erb. Let&#8217;s edit the file to look like this:</p>
<pre>xml.instruct! <img src='http://www.metabates.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ml, :version=&gt;"1.0"
xml.rss(:version =&gt; "2.0") do
  xml.channel do
    xml.title("My Mack Blog")
    xml.link(posts_index_full_url)
    xml.description("Find out about all the cool stuff happening on my blog!")
    xml.language("en-us")
    xml.copyright("Copyright Me")
    xml.pubDate(CGI.rfc1123_date(Time.now))
    xml.lastBuildDate(CGI.rfc1123_date(Time.now))
    @posts.each do |post|
      xml.entry do
        xml.title(post.title)
        xml.link(posts_show_full_url(:id =&gt; post.id))
        xml.description(post.body)
        xml.pubDate(post.created_at.strftime("%a, %d %b %Y %H:%M:%S"))
      end
    end
  end
end</pre>
<p>Mack uses the standard builder gem library. I&#8217;m not going to go into explaining how that works, there are plenty of other tutorials and documentation that will show you that. I&#8217;m also not going to explain all the necessary pieces of an RSS feed. Instead I&#8217;ll point out in that code you&#8217;ll see we&#8217;re using the @posts instance variable that we set in the index action of our PostsController. Just like regular *.html.erb files we have access to all the instance variables from the controller, as well, helpers, etc&#8230;</p>
<p>So now if we go to http://localhost:3000/posts.xml we should see our RSS feed. If we did a view source we should see something that looks like this:</p>
<pre id="line1"><span class="pi">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>
&lt;<span class="start-tag">rss</span><span class="attribute-name"> version</span>=<span class="attribute-value">"2.0"</span>&gt;
 &lt;<span class="start-tag">channel</span>&gt;
  &lt;<span class="start-tag">title</span>&gt;My Mack Blog&lt;/<span class="end-tag">title</span>&gt;
  &lt;<span class="start-tag">link</span>&gt;http://localhost:3000/posts&lt;/<span class="end-tag">link</span>&gt;
  &lt;<span class="start-tag">description</span>&gt;Find out about all the cool stuff happening on my blog!&lt;/<span class="end-tag">description</span>&gt;
  &lt;<span class="start-tag">language</span>&gt;en-us&lt;/<span class="end-tag">language</span>&gt;
  &lt;<span class="start-tag">copyright</span>&gt;Copyright Me&lt;/<span class="end-tag">copyright</span>&gt;</pre>
<pre id="line9">  &lt;<span class="start-tag">pubDate</span>&gt;Tue, 18 Mar 2008 17:18:05 GMT&lt;/<span class="end-tag">pubDate</span>&gt;
  &lt;<span class="start-tag">lastBuildDate</span>&gt;Tue, 18 Mar 2008 17:18:05 GMT&lt;/<span class="end-tag">lastBuildDate</span>&gt;
  &lt;<span class="start-tag">entry</span>&gt;
   &lt;<span class="start-tag">title</span>&gt;My New Post&lt;/<span class="end-tag">title</span>&gt;
   &lt;<span class="start-tag">link</span>&gt;http://localhost:3000/posts/1&lt;/<span class="end-tag">link</span>&gt;
   &lt;<span class="start-tag">description</span>&gt;This is my first post in my cool Mack blog!&lt;/<span class="end-tag">description</span>&gt;</pre>
<pre id="line15">   &lt;<span class="start-tag">pubDate</span>&gt;Tue, 18 Mar 2008 11:58:30&lt;/<span class="end-tag">pubDate</span>&gt;
  &lt;/<span class="end-tag">entry</span>&gt;
 &lt;/<span class="end-tag">channel</span>&gt;
&lt;/<span class="end-tag">rss</span>&gt;</pre>
<p>Awesome! All that&#8217;s really left is create one of those fancy RSS tags in the location field of our browsers that people can click and go straight to the RSS feed. Let&#8217;s do that now.</p>
<p>At the top of your app/views/posts/index.html.erb file add the following:</p>
<pre>&lt;%= rss_tag(posts_index_url(:format =&gt; <img src='http://www.metabates.com/wp-includes/images/smilies/icon_mad.gif' alt=':x' class='wp-smiley' /> ml)) %&gt;</pre>
<p>Now, refresh the page in your browser, and there you go, you should now see the little RSS button in the location bar of your browser. If you click that you should be taken to your feed.</p>
<p>That&#8217;s all there is to adding not only xml, but an RSS feed to your new blog.</p>
<p>The code for this demo can be found <a href="http://www.mackframework.com/wp-content/uploads/2008/03/mack_blog_demo.zip" title="Blog Demo w/ XML">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.metabates.com/2008/03/19/adding-rssxml-feeds-to-our-blog-demo/feed/</wfw:commentRss>
		<slash:comments>1</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.310 seconds -->
