<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Andrew Degenhardt's Weblog</title>
	<atom:link href="http://andrewdegenhardt.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewdegenhardt.wordpress.com</link>
	<description>news and technology</description>
	<lastBuildDate>Wed, 09 Feb 2011 19:51:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='andrewdegenhardt.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Andrew Degenhardt's Weblog</title>
		<link>http://andrewdegenhardt.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://andrewdegenhardt.wordpress.com/osd.xml" title="Andrew Degenhardt&#039;s Weblog" />
	<atom:link rel='hub' href='http://andrewdegenhardt.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Transfer Ruby on Rails app, and mysql to sqlite</title>
		<link>http://andrewdegenhardt.wordpress.com/2009/12/14/transfer-ruby-on-rails-app-and-mysql-to-sqlite/</link>
		<comments>http://andrewdegenhardt.wordpress.com/2009/12/14/transfer-ruby-on-rails-app-and-mysql-to-sqlite/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 07:15:37 +0000</pubDate>
		<dc:creator>andrewdegenhardt</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[step by step]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sqlite]]></category>
		<category><![CDATA[transfer]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[publickey]]></category>
		<category><![CDATA[Permission denied]]></category>
		<category><![CDATA[hung up]]></category>
		<category><![CDATA[yml]]></category>
		<category><![CDATA[yaml]]></category>
		<category><![CDATA[backup.rake]]></category>

		<guid isPermaLink="false">http://andrewdegenhardt.wordpress.com/?p=104</guid>
		<description><![CDATA[I just finished transferring a Ruby on Rails web site from one server to another and also transferring the data from MYSQL to sqlite. I solved all the problems with some help from Pat, and learned along the way. The first problem was with my deployment using capistrano. Setting up the git repository, pushing it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=104&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just finished transferring a Ruby on Rails web site from one server to another and also transferring the data from MYSQL to sqlite. I solved all the problems with some help from Pat, and learned along the way.</p>
<p>The first problem was with my deployment using capistrano. Setting up the git repository, pushing it up&#8211;that was easy. For some reason my deployments were not working. Git pushes and pulls worked, and I could log into the server via ssh just fine. And when I did log in via ssh, I had to type my password. So I figured that my ssh public/private keys were not uploaded to the server. So I asked my server admin to update my ssh keys, and I emailed him the contents of my .ssh dir so he could dump them in my remote home dir.</p>
<p>This still did not resolve the problem.</p>
<p>Here is what my cap deploy would result in:<br />
<em><br />
[76.73.15.5] executing command<br />
** [76.73.15.5 :: err] Permission denied, please try again.<br />
** [76.73.15.5 :: err] Permission denied, please try again.<br />
** [76.73.15.5 :: err] Permission denied (publickey,password).<br />
** fatal: The remote end hung up unexpectedly<br />
command finished<br />
*** [deploy:update_code] rolling back<br />
* executing &#8220;rm -rf /home/andrew/apps/kpmstaffing/releases/20091207060339; true&#8221;<br />
servers: ["76.73.15.5"]<br />
[76.73.15.5] executing command<br />
command finished<br />
failed: &#8220;sh -c &#8216;git clone -q ssh://andrew@76.73.15.5/home/andrew/git/kpmstaffing /home/andrew/apps/kpmstaffing/releases</em></p>
<p>so after a while of fumbling around on my part, and expert looking and inspecting from my server admin, it was found that the problem was with my .ssh/* contents, something was wrong with those files and it was preventing my capistrano to deploy properly via ssh. So, the solution was some expert use of ssh-copy-id on the remote server. Or you could just resend your .ssh public/private keys somehow if you have this problem.</p>
<p>So now my cap deploy would work. The next step was to transfer the database from the live Web site to the new location.</p>
<p>This proved to be quite a task, even though I have done this before and I thought it was going to be easy. Well, there turned out to be some variables that I did not encounter before.</p>
<p>First rudiment, you have to have this file: <span style="text-decoration:underline;">backup.rake</span>. I dont know where to get it from, I just had it from a project I worked on with a friend.</p>
<p>First thing I did was get a copy of the yml file that was automatically being made daily and sent to an email account that I have set up. I copied this file to my local computer.</p>
<p>Now, I also, just for fun, ran this command on the live web site:<br />
<strong>rake db:backup:write</strong></p>
<p>that created another yml file in db/backup/ on the remote server.</p>
<p>So now I had the auto backup yml file, and I could also make a backup yml file of the database any time I wanted. Now what?</p>
<p>Well, I was transferring from mysql to sqlite. So mysql wasnt a problem area because when I did the db:backup:write it just dumped all the data to a yml file in db/backup/. No problem. But on the new location of my web app, it is a bit different because you have to set up a shared db for sqlite. So first thing you have to do is alter your database.yml file to look like this in production:</p>
<p><strong>production:<br />
adapter: sqlite3<br />
database: /home/andrew/apps/kpmstaffing/shared/db/production.sqlite3<br />
pool: 5<br />
timeout: 5000</strong></p>
<p>Then, you have to do a <strong>cap deploy:migrate</strong> from the local computer, that puts some version of the database there, just something but its not your end product. BUT it should be the correct schema, just the data is not up to date.</p>
<p>Then you have to load the data in there, so get your latest backup yml file, and dump it into db/backup/ on the remote server into the correct version of the app. If you are using git then you will know what I&#8217;m talking about here.</p>
<p>now run these commands on the remote server:</p>
<p><strong>rake db:migrate:reset RAILS_ENV=&#8217;production&#8217;<br />
rake db:restore RAILS_ENV=&#8217;production&#8217;</strong></p>
<p>That should put the data into the new shared db location. The db:restore command uses the latest file in db/backup/ and dumps data into the database.</p>
<p>Now, if you want to test it, run this on remote server:</p>
<p><strong>./script/server -p 3001 -e production</strong></p>
<p>Use whatever port you want to use, but definitely use <strong>&#8216;-e production&#8217;</strong> or your test run will use the development database.</p>
<p>Now for some reason, I had some instructions from before to run this command to load the data into the tables:</p>
<p><strong>rake db:backup:read RAILS_ENV=&#8217;production&#8217;</strong></p>
<p>That ALWAYS failed and gave me this error:</p>
<p><em>rake aborted!<br />
Don&#8217;t know how to build task &#8216;db:backup:read&#8217;</em></p>
<p>And I was stuck on this for a while. Finally I opened up backup.rake in lib/tasks/ to see how this file worked, and I noticed that there was no backup:read command, just &#8220;restore&#8221;. So I changed it to <strong>db:restore RAILS_ENV=&#8217;production&#8217;</strong> and it worked.</p>
<p>So now my website is running. Thanks Pat for the help.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrewdegenhardt.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrewdegenhardt.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrewdegenhardt.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrewdegenhardt.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrewdegenhardt.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrewdegenhardt.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrewdegenhardt.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrewdegenhardt.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrewdegenhardt.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrewdegenhardt.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrewdegenhardt.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrewdegenhardt.wordpress.com/104/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrewdegenhardt.wordpress.com/104/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrewdegenhardt.wordpress.com/104/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=104&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewdegenhardt.wordpress.com/2009/12/14/transfer-ruby-on-rails-app-and-mysql-to-sqlite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">andrewdegenhardt</media:title>
		</media:content>
	</item>
		<item>
		<title>show a database record by word instead of an id number, ruby on rails guide</title>
		<link>http://andrewdegenhardt.wordpress.com/2009/08/07/show-a-database-record-by-word-instead-of-an-id-number-ruby-on-rails-guide/</link>
		<comments>http://andrewdegenhardt.wordpress.com/2009/08/07/show-a-database-record-by-word-instead-of-an-id-number-ruby-on-rails-guide/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 20:45:22 +0000</pubDate>
		<dc:creator>andrewdegenhardt</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[friendly url]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[id]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[path]]></category>
		<category><![CDATA[recordnotfound]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[shortname]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[word]]></category>

		<guid isPermaLink="false">http://andrewdegenhardt.wordpress.com/?p=99</guid>
		<description><![CDATA[These instructions are to show you how to use a word in the url instead of an ID.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=99&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>These instructions are to show you how to use a word in the url instead of an ID.</p>
<p>Like having a url that looks like this:</p>
<p>http://www.comickeith.com/biographies/keith</p>
<p>instead of</p>
<p>http://www.comickeith.com/biographies/1</p>
<p>This is much better for Search Engine Optimization, friendly urls for the public, easy to remember, and just looks better.</p>
<p>These instructions assume that you don&#8217;t have a &#8220;shortname&#8221; field in your table yet.</p>
<p>1 in your command line interface, inside the project directory, run this:</p>
<p>script/generate migration add_shortname</p>
<p>2 open the file db/migrate/LATESTTIMSTAMP_add_shortname.rb</p>
<p>This is the code that should be inside the class:</p>
<p>def self.up</p>
<p style="padding-left:30px;">add_column &#8220;pages&#8221;, &#8220;shortname&#8221;, :string</p>
<p>end</p>
<p>def self.down</p>
<p style="padding-left:30px;">remove_column &#8220;pages&#8221;, &#8220;shortname&#8221;</p>
<p>end</p>
<p>The &#8220;up&#8221; is run when you migrate, the &#8220;down&#8221; is run if you rollback</p>
<p>2b Run this at your command line:</p>
<p>rake db:migrate</p>
<p>3 open app/views/admin/Pages/_form.html.erb</p>
<p>Add this into the form:</p>
<p>&lt;tr&gt;&lt;td&gt;&lt;p&gt;&lt;label&gt;Short Name:&amp;nbsp;&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;%= f.text_field :shortname %&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;</p>
<p>3 open the Page model in app/models/page.rb</p>
<p>Add these two lines:</p>
<p>validates_presence_of :shortname<br />
validates_uniqueness_of :shortname</p>
<p>3b now go into your website into the admin section and put shortnames in all your records, you have to or you&#8217;ll get errors if you go on.</p>
<p>If you don&#8217;t have your web forms done for your adminstrative area, better go do that now, because you won&#8217;t be able to finish this target. or you can put data in the database using another way. but I suggest getting the admin forms done now. it will save you time in the long run.<br />
See <a href="http://andrewdegenhardt.wordpress.com/2009/03/12/create-a-list-of-database-items-using-ruby-on-rails-in-the-administrative-area" target="_blank">Create administrative area in ruby on rails</a></p>
<p>4 open app/controllers/pages_controller.rb, and add the following code:</p>
<p>#this line goes outside the defs, at the top of the class<br />
rescue_from ActiveRecord::RecordNotFound, :with =&gt; :rec_not_found</p>
<p>#add the following code:<br />
def show</p>
<p style="padding-left:30px;">if params[:id].nil?</p>
<p style="padding-left:60px;">@page = Page.find(:first)</p>
<p style="padding-left:30px;">else</p>
<p style="padding-left:60px;">@page = Page.find_by_shortname(params[:id])<br />
raise ActiveRecord::RecordNotFound unless @page</p>
<p style="padding-left:30px;">end</p>
<p>end</p>
<p>def rec_not_found</p>
<p style="padding-left:30px;">@page = Page.find(:first)<br />
render :action=&gt;&#8217;show&#8217;</p>
<p>end</p>
<p>5 open app/views/layouts/application.erb and change the following line of code in the loop:</p>
<p>&lt;%=link_to page.title, &#8220;/pages/&#8221;+ page.shortname  , :class =&gt; &#8220;smlink&#8221; %&gt;</p>
<p>In order for the above line of code to work you have to have some other function put in which is in my other blog posts.</p>
<p>If you don&#8217;t have that function in, you can just hard code a link so see that it works or type it in the browser address, like this:</p>
<p>&lt;a href=&#8221;/pages/profile&#8221;&gt;Profile&lt;/a&gt;</p>
<p>or see <a href="http://andrewdegenhardt.wordpress.com/2009/03/12/create-a-list-of-database-items-using-ruby-on-rails-in-the-administrative-area/" target="_blank">create a list of database items in admin area</a><br />
for how to create a basic loop that you can put in application.erb</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrewdegenhardt.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrewdegenhardt.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrewdegenhardt.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrewdegenhardt.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrewdegenhardt.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrewdegenhardt.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrewdegenhardt.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrewdegenhardt.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrewdegenhardt.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrewdegenhardt.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrewdegenhardt.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrewdegenhardt.wordpress.com/99/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrewdegenhardt.wordpress.com/99/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrewdegenhardt.wordpress.com/99/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=99&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewdegenhardt.wordpress.com/2009/08/07/show-a-database-record-by-word-instead-of-an-id-number-ruby-on-rails-guide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">andrewdegenhardt</media:title>
		</media:content>
	</item>
		<item>
		<title>force rails to using show.html.erb from def index in the controller, how to</title>
		<link>http://andrewdegenhardt.wordpress.com/2009/06/10/force-rails-to-using-show-html-erb-from-def-index-in-the-controller-how-to/</link>
		<comments>http://andrewdegenhardt.wordpress.com/2009/06/10/force-rails-to-using-show-html-erb-from-def-index-in-the-controller-how-to/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 21:43:23 +0000</pubDate>
		<dc:creator>andrewdegenhardt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[:action]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[def index]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[public]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[render]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[show]]></category>
		<category><![CDATA[show.html.erb]]></category>
		<category><![CDATA[step by step]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://andrewdegenhardt.wordpress.com/?p=83</guid>
		<description><![CDATA[This will force the use of show.html.erb when the public requests yourdomain.com/pages/<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=83&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So now you have some basics put into your Web site, and you are ready to show some data to the public site. But you want to make the <em>def index</em> code in your controller use the show.html.erb.</p>
<p>1. Open pages_controller.rb</p>
<p>def index</p>
<p style="padding-left:30px;">@pages = Page.find(:all, :order =&gt; &#8220;page_order ASC&#8221;)</p>
<p style="padding-left:30px;">@page = Page.find(:first, :order =&gt; :page_order)<br />
render :action=&gt;&#8217;show&#8217;</p>
<p>end</p>
<p>This will force the use of show.html.erb when the public requests yourdomain.com/pages/</p>
<p>So in the query, it selects the first page in the Database. Because there is no ID sent from the path above, just /pages/ , so you gotta do this in the controller</p>
<p>The @pages query is for your navigation menu at the top, if you decide to make that part of your project dynamic. I&#8217;m pretty sure that I have the code somewhere in this blog to show how that works in the application view. look for listing of items in the titles for how to display that menu of page links.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrewdegenhardt.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrewdegenhardt.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrewdegenhardt.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrewdegenhardt.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrewdegenhardt.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrewdegenhardt.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrewdegenhardt.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrewdegenhardt.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrewdegenhardt.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrewdegenhardt.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrewdegenhardt.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrewdegenhardt.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrewdegenhardt.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrewdegenhardt.wordpress.com/83/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=83&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewdegenhardt.wordpress.com/2009/06/10/force-rails-to-using-show-html-erb-from-def-index-in-the-controller-how-to/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">andrewdegenhardt</media:title>
		</media:content>
	</item>
		<item>
		<title>Add form validation for Ruby on Rails app, for the admin namespace, a guide</title>
		<link>http://andrewdegenhardt.wordpress.com/2009/03/18/add-form-validation-for-ruby-on-rails-app-for-the-admin-namespace-a-guide/</link>
		<comments>http://andrewdegenhardt.wordpress.com/2009/03/18/add-form-validation-for-ruby-on-rails-app-for-the-admin-namespace-a-guide/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 07:33:17 +0000</pubDate>
		<dc:creator>andrewdegenhardt</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[error_messages_for]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[instructions]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[number validation]]></category>
		<category><![CDATA[step by step]]></category>
		<category><![CDATA[validate]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://andrewdegenhardt.wordpress.com/?p=77</guid>
		<description><![CDATA[This blog entry is for adding form validation to your admin section. You can also use these instructions for your public side validation. 1 open the file app/models/page.rb Add this into the file: validates_presence_of :shortname validates_uniqueness_of :shortname validates_numericality_of :page_order validates_presence_of :title validates_presence_of :content If you don&#8217;t know why there is a shortname in the model, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=77&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This blog entry is for adding form validation to your admin section. You can also use these instructions for your public side validation.</p>
<p><strong>1</strong> open the file app/models/page.rb</p>
<p><em>Add this into the file:</em></p>
<p style="padding-left:30px;"><span> </span>validates_presence_of :shortname</p>
<p style="padding-left:30px;"><span> </span>validates_uniqueness_of :shortname</p>
<p style="padding-left:30px;"><span> </span>validates_numericality_of :page_order</p>
<p style="padding-left:30px;"><span> </span>validates_presence_of :title</p>
<p style="padding-left:30px;"><span> </span>validates_presence_of :content</p>
<p>If you don&#8217;t know why there is a <em>shortname</em> in the model, that&#8217;s ok. You may not have read the blog regarding this field. There will be a blog made for that field.</p>
<p><strong>2 </strong>Open this file, or create it:  public/stylesheets/admin.css</p>
<p><em>Put this into the file, you can change it if you want:</em></p>
<p>.fieldWithErrors {</p>
<p style="padding-left:30px;"><span> </span>border-left: 10px solid #b00000;</p>
<p style="padding-left:30px;"><span> </span>width: 400px;</p>
<p style="padding-left:30px;"><span> </span>border-left-color:#b00000</p>
<p><span> </span>}</p>
<p><span> </span></p>
<p>.errorExplanation{</p>
<p style="padding-left:30px;"><span> </span>color:#b00000</p>
<p>}</p>
<p><strong>3</strong> Go into these files: app/views/admin/pages/edit.html.erb and new.html.erb</p>
<p><em>Make sure the following code is somewhere in the file, preferably at the top:</em></p>
<p>&lt;font color=&#8221;red&#8221;&gt;</p>
<p style="padding-left:30px;">&lt;%= error_messages_for &#8216;page&#8217; %&gt; # &#8216;page&#8217; is the model name</p>
<p>&lt;/font&gt;</p>
<p>This will show error messages on your page if there is a validation error. Test it and you will see.</p>
<div></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrewdegenhardt.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrewdegenhardt.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrewdegenhardt.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrewdegenhardt.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrewdegenhardt.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrewdegenhardt.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrewdegenhardt.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrewdegenhardt.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrewdegenhardt.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrewdegenhardt.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrewdegenhardt.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrewdegenhardt.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrewdegenhardt.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrewdegenhardt.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=77&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewdegenhardt.wordpress.com/2009/03/18/add-form-validation-for-ruby-on-rails-app-for-the-admin-namespace-a-guide/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">andrewdegenhardt</media:title>
		</media:content>
	</item>
		<item>
		<title>create simple public database driven web site in Ruby on Rails, step by step guide</title>
		<link>http://andrewdegenhardt.wordpress.com/2009/03/16/create-simple-public-database-driven-web-site-in-ruby-on-rails-step-by-step-guide/</link>
		<comments>http://andrewdegenhardt.wordpress.com/2009/03/16/create-simple-public-database-driven-web-site-in-ruby-on-rails-step-by-step-guide/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 04:23:14 +0000</pubDate>
		<dc:creator>andrewdegenhardt</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[css and ruby]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[instructions]]></category>
		<category><![CDATA[public]]></category>
		<category><![CDATA[public site]]></category>
		<category><![CDATA[routes.rb]]></category>
		<category><![CDATA[show item]]></category>
		<category><![CDATA[simple page]]></category>
		<category><![CDATA[step by step]]></category>
		<category><![CDATA[stylsheets]]></category>
		<category><![CDATA[using routes]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://andrewdegenhardt.wordpress.com/?p=75</guid>
		<description><![CDATA[This blog entry is for setting up the public site of your Web application.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=75&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This blog entry is for setting up the public site of your Web application.</p>
<p>You should do the administrative site first, so you can create and edit test data.</p>
<p>1 First, delete public/index.html</p>
<p>2 script/generate controller Pages show index</p>
<p><em>This is another controller in a different namespace than the admin/Pages controller. It uses the same model as the admin controller.</em></p>
<p>3 open up this file: app/controllers/pages_controller.rb</p>
<p><em>Add this code to the controller. There is a simple test here in this code, checking in case the parameter is null.</em></p>
<p><span> </span>def show</p>
<p style="padding-left:30px;"><span> </span>if params[:id].nil?</p>
<p style="padding-left:60px;"><span> </span>@page = Page.find(:first, :order =&gt; :page_order)</p>
<p style="padding-left:30px;"><span> </span>else</p>
<p style="padding-left:60px;"><span> </span>@page = Page.find(params[:id])</p>
<p style="padding-left:30px;"><span> </span>end</p>
<p><span> </span>end</p>
<p>4 open config/routes.rb</p>
<p><em>Add the following lines of code, and comment out the other lines, not needed in our app right now.</em></p>
<p><em>You can change your root controller later if your app changes or you want to load a different controller for the root of the application.</em></p>
<p>map.resources :pages</p>
<p>map.root :controller =&gt; &#8220;Pages&#8221;</p>
<p>#comment the next two lines out</p>
<p>#map.connect &#8216;:controller/:action/:id&#8217;</p>
<p>#map.connect &#8216;:controller/:action/:id.:format&#8217;</p>
<p>5 open up the app/controllers/pages_controller.rb</p>
<p style="padding-left:60px;"><em>put this code into the index def:</em></p>
<p>def index</p>
<p style="padding-left:30px;">@page = Page.find(:first, :order =&gt; :page_order)</p>
<p style="padding-left:30px;"><span> </span>render :action=&gt;&#8217;show&#8217;</p>
<p><span> </span>end</p>
<p>6 create the file app/views/layouts/application.html.erb</p>
<p><em>This is where you put your main layout, made up of html code, of course.</em></p>
<p><em>Inside the content area of your html layout, put this line of code:</em></p>
<p>&lt;%=yield %&gt;</p>
<p><em>You can start out by putting only the above line of code in this file.</em></p>
<p><em>This will pull the layout from the views of each of the controllers. The controller executed depends on the path in the URL.</em></p>
<p><strong>7</strong> create the file: app/views/pages/show.html.erb</p>
<p>This is your view for the Pages controller. It allows you to create an html view that will fit into application.html.erb.</p>
<p>Put this one line of code into the file, you can build up your html around this now or later:</p>
<p>&lt;%= @page.content %&gt;</p>
<p><strong>8 </strong>If you have any image files, put them into /public/images/</p>
<p><em>to reference them, use this path:</em></p>
<p>src=&#8221;/images/hdlogo.png&#8221;</p>
<p><strong>9</strong> Put your css file into /public/stylesheets/</p>
<p>The path to your css file is as follows:</p>
<p>href=&#8221;/stylesheets/style1.css&#8221;</p>
<p><strong>10</strong> see the blog post called &#8220;create a list of database items using Ruby on Rails&#8230;&#8221;, this will show you how to make a listing of links on your index.html.erb, then you can link to the above show page in application.hrml.erb. You will see how it all fits together once you do all the instructions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrewdegenhardt.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrewdegenhardt.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrewdegenhardt.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrewdegenhardt.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrewdegenhardt.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrewdegenhardt.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrewdegenhardt.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrewdegenhardt.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrewdegenhardt.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrewdegenhardt.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrewdegenhardt.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrewdegenhardt.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrewdegenhardt.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrewdegenhardt.wordpress.com/75/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=75&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewdegenhardt.wordpress.com/2009/03/16/create-simple-public-database-driven-web-site-in-ruby-on-rails-step-by-step-guide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">andrewdegenhardt</media:title>
		</media:content>
	</item>
		<item>
		<title>Adding security to your Ruby on Rails application, to the administrative section, a guide</title>
		<link>http://andrewdegenhardt.wordpress.com/2009/03/13/adding-security-to-your-ruby-on-rails-application-to-the-administrative-section-a-guide/</link>
		<comments>http://andrewdegenhardt.wordpress.com/2009/03/13/adding-security-to-your-ruby-on-rails-application-to-the-administrative-section-a-guide/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 07:13:25 +0000</pubDate>
		<dc:creator>andrewdegenhardt</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[administrative]]></category>
		<category><![CDATA[content management]]></category>
		<category><![CDATA[controller security]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[instructions]]></category>
		<category><![CDATA[login and password]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[simple security]]></category>
		<category><![CDATA[step by step]]></category>

		<guid isPermaLink="false">http://andrewdegenhardt.wordpress.com/?p=70</guid>
		<description><![CDATA[This article is for adding a simple security into your administrative section of your Ruby on Rails Web app.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=70&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This article is for adding a simple security into your administrative namespace. You will have to do step one for each of the controllers in your admin namespace.</p>
<p>This is also where you set up the entry point where your client will log in to the administrative area of your web app.</p>
<p><strong>1</strong> open app/controllers/admin/pages_controller.rb</p>
<p><em>put this line of code at the top of the class definition</em></p>
<p>verify :session =&gt; :admin, :add_flash =&gt; {:notice =&gt; &#8220;Invalid Access&#8221;}, :redirect_to =&gt; :admin_users_path</p>
<p><strong>2</strong> run this code in your terminal, in your project directory:</p>
<p>script/generate controller admin/users</p>
<p><strong>3</strong> open the file called app/controllers/admin/users_controller.rb</p>
<p><em>*Note: You will need to make a separate layout file for the login screen, one that does not have the menu items at the top; the instructions for this point are later in this blog entry.</em></p>
<p><em>Put this code into the controller:</em></p>
<p>#administrative layout designation:</p>
<p>layout &#8220;users&#8221;</p>
<p>def create</p>
<p style="padding-left:30px;">if params[:username] == &#8216;admin&#8217;  &amp;&amp; params[:password] == &#8216;MyPassword&#8217;</p>
<p style="padding-left:60px;">flash[:notice] = &#8216;Login successful.&#8217;</p>
<p style="padding-left:60px;">redirect_to admin_pages_path</p>
<p style="padding-left:60px;">session[:admin] = true</p>
<p style="padding-left:30px;">else</p>
<p style="padding-left:60px;">session[:admin] = nil</p>
<p style="padding-left:60px;">flash[:notice] = &#8216;Login unsuccessful.&#8217;</p>
<p style="padding-left:60px;">render :action =&gt; &#8216;index&#8217;</p>
<p style="padding-left:30px;">end</p>
<p>end</p>
<p>def show</p>
<p style="padding-left:30px;">flash[:notice] = &#8216;You have logged out successfully.&#8217;</p>
<p style="padding-left:30px;">session[:admin] = nil</p>
<p style="padding-left:30px;">redirect_to admin_users_path</p>
<p>end</p>
<p><strong>4</strong> create the file app/views/layouts/users.html.erb</p>
<p><em>Put this into the file:</em></p>
<p>&lt;%=yield %&gt;</p>
<p>This is the bare minimum that one can put into a layout file, once your public layout is designed, you can copy that layout and build it around the above yield statement, so that your login page looks good.</p>
<p><strong>4</strong> go into this file: app/views/admin/pages/index.html.erb</p>
<p><em>Make sure this line of code is somewhere near the top of the page. This allows for messages to be passed to the Pages controller from the admin controller&#8211;or from any controller to the Pages controller.</em></p>
<p>&lt;font color=&#8221;red&#8221;&gt;&lt;%= flash[:notice] %&gt;&lt;/font&gt;&lt;br&gt;</p>
<p><strong>5 </strong>open up, or create this file: app/views/admin/users/index.html.erb</p>
<p>&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;</p>
<p>&lt;head&gt;</p>
<p>&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=utf-8&#8243; /&gt;</p>
<p>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;/stylesheets/admin.css&#8221;&gt;</p>
<p>&lt;title&gt;My Company::Administration:Login&lt;/title&gt;</p>
<p>&lt;/head&gt;</p>
<p>&lt;body&gt;</p>
<p><span> </span>&lt;h1&gt;My company Administration Login&lt;/h1&gt;</p>
<p><span> </span>&lt;font color=&#8221;red&#8221;&gt;&lt;%= flash[:notice] %&gt;&lt;/font&gt;</p>
<p>&lt;p&gt;Type your user name and password:&lt;/p&gt;</p>
<p>&lt;%=form_tag(&#8216;/admin/users&#8217;, :method =&gt; :post)%&gt;</p>
<p>&lt;table border=&#8221;0&#8243; cellpadding=&#8221;0&#8243; cellspacing=&#8221;0&#8243;&gt;</p>
<p>&lt;tr&gt;&lt;td&gt;</p>
<p>&lt;label&gt;User Name:&lt;/label&gt;&lt;/td&gt;&lt;td&gt; &lt;%=text_field_tag &#8220;username&#8221; %&gt;&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;tr&gt;&lt;td&gt;&lt;label&gt;Password:&lt;/label&gt;&lt;/td&gt;&lt;td&gt; &lt;%=password_field_tag &#8220;password&#8221;  %&gt;&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;tr&gt;&lt;td colspan=&#8221;2&#8243; align=&#8221;left&#8221;&gt;&lt;label&gt;&amp;nbsp;&lt;/label&gt;&lt;%= submit_tag &#8220;Log In&#8221; %&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;/table&gt;</p>
<p>&lt;/form&gt;</p>
<p>&lt;/body&gt;</p>
<p>&lt;/html&gt;</p>
<p><strong>6 </strong>open up config/routes.rb</p>
<p><em>add the following line of code inside the admin namespace, look for this section of routes.rb: </em></p>
<p style="padding-left:30px;"><em>&#8220;map.namespace :admin do |admin|&#8221;</em></p>
<p>admin.resources :users</p>
<p><em>if the user tries to get to /admin/pages without logging in properly, it will redirect the user to /admin/users with a message &#8220;Invalid Access&#8221;.</em></p>
<p><strong>7</strong> The path to the login page is:</p>
<p>http://localhost:3000/admin/users</p>
<p>This is an excercise in learning Rails. The seemingly &#8220;understood&#8221; factor of the flash[:notice] variable being available in the view is a feature of Rails.</p>
<p>Also, the statement &#8220;=yield&#8221; in Ruby code allowing you to pull html from another view file is a feature of Rails. These are things about Rails that you cannot see objectively, but learn from experience or reading good books.</p>
<p>Enjoy! Let me know if there are any questions or problems using this guide.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrewdegenhardt.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrewdegenhardt.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrewdegenhardt.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrewdegenhardt.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrewdegenhardt.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrewdegenhardt.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrewdegenhardt.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrewdegenhardt.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrewdegenhardt.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrewdegenhardt.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrewdegenhardt.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrewdegenhardt.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrewdegenhardt.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrewdegenhardt.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=70&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewdegenhardt.wordpress.com/2009/03/13/adding-security-to-your-ruby-on-rails-application-to-the-administrative-section-a-guide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">andrewdegenhardt</media:title>
		</media:content>
	</item>
		<item>
		<title>Create add, edit, and show pages for administrative area, Ruby on Rails</title>
		<link>http://andrewdegenhardt.wordpress.com/2009/03/12/create-add-edit-and-show-pages-for-administrative-area-ruby-on-rails/</link>
		<comments>http://andrewdegenhardt.wordpress.com/2009/03/12/create-add-edit-and-show-pages-for-administrative-area-ruby-on-rails/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 07:33:49 +0000</pubDate>
		<dc:creator>andrewdegenhardt</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[add]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[administrative]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[edit]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[instructions]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[preview]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[step by step]]></category>
		<category><![CDATA[view]]></category>
		<category><![CDATA[working copy]]></category>

		<guid isPermaLink="false">http://andrewdegenhardt.wordpress.com/?p=63</guid>
		<description><![CDATA[This blog entry is for showing you how to link your admin listing page to your add, edit and show pages. <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=63&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This blog entry is for showing you how to link your admin listing page to your add, edit and show pages. There are four files that you have to make here. There is something called scaffolding, which saves you time and typing, but it&#8217;s good to drill this approach so that you understand how Rails works. Scaffolding will be posted later. But once you understand this, you should be able to figure out scaffolding yourself.</p>
<p><strong>1</strong> create or open this file: app/views/admin/pages/edit.html.erb</p>
<p><em>Put this code into the file:</em></p>
<p>&lt;h1&gt;Edit Page&lt;/h1&gt;</p>
<p>&lt;p&gt;You are now editing page: &lt;%= @page.title %&gt;&lt;/p&gt;</p>
<p>&lt;font color=&#8221;red&#8221;&gt;</p>
<p>&lt;%= error_messages_for &#8216;page&#8217; %&gt;</p>
<p>&lt;/font&gt;</p>
<p>&lt;% form_for([:admin, @page]) do |f| %&gt;</p>
<p>&lt;%= render :partial =&gt; &#8220;form&#8221;, :locals=&gt;{:f=&gt;f} %&gt;</p>
<p>&lt;p&gt;&lt;label&gt;&amp;nbsp;&lt;/label&gt;&lt;%= f.submit &#8220;Update&#8221; %&gt;&amp;nbsp;&lt;/p&gt;</p>
<p>&lt;% end %&gt;</p>
<p><strong>2</strong> create or open this file: app/views/admin/pages/new.html.erb</p>
<p><em>This is the code you put into this file:</em></p>
<p>&lt;h1&gt;New Page&lt;/h1&gt;</p>
<p>&lt;p&gt;You are now adding a new page:&lt;/p&gt;</p>
<p>&lt;font color=&#8221;red&#8221;&gt;</p>
<p>&lt;%= error_messages_for &#8216;page&#8217; %&gt;</p>
<p>&lt;/font&gt;</p>
<p>&lt;br&gt;</p>
<p>&lt;% form_for([:admin, @page]) do |f| %&gt;</p>
<p>&lt;%= render :partial =&gt; &#8220;form&#8221;, :locals=&gt;{:f=&gt;f} %&gt;</p>
<p>&lt;p&gt;&lt;%= f.submit &#8220;Save&#8221; %&gt;&amp;nbsp;&lt;/p&gt;</p>
<p>&lt;% end %&gt;</p>
<p><strong>2</strong> Create this file: app/views/admin/pages/_form.html.erb</p>
<p><em>Put this code into the file:</em></p>
<p>&lt;table&gt;</p>
<p>&lt;tr&gt;&lt;td&gt;&lt;p&gt;&lt;label&gt;Title:&amp;nbsp;&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;%= f.text_field :title %&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;tr&gt;&lt;td&gt;&lt;p&gt;&lt;label&gt;Short Name:&lt;br&gt;&lt;small&gt;This is the name&lt;br&gt;that will show in&lt;br&gt;the address path, &lt;br&gt;for About Us, &lt;br&gt;put aboutus&lt;/small&gt;&amp;nbsp;&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;%= f.text_field :shortname %&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;tr&gt;&lt;td width=&#8221;100&#8243;&gt;&lt;label&gt;Description:&amp;nbsp;&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;%= f.text_field :description %&gt;&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;tr&gt;&lt;td colspan=&#8221;2&#8243;&gt;&lt;label&gt;Tags:&amp;nbsp;&lt;/label&gt;&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;tr&gt;&lt;td colspan=&#8221;2&#8243;&gt;</p>
<p>&lt;%= f.text_area :tags, :cols =&gt; 50, :rows =&gt; 10 %&gt;</p>
<p>&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;tr&gt;&lt;td colspan=&#8221;2&#8243;&gt;&lt;p&gt;&lt;label&gt;Web Page Content:&lt;/label&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;tr&gt;&lt;td colspan=&#8221;2&#8243;&gt;&lt;p&gt;&lt;%= f.text_area :content, :cols =&gt; 100, :rows =&gt; 15 %&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;tr&gt;&lt;td width=&#8221;100&#8243;&gt;&lt;label&gt;Robots:&amp;nbsp;&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;%= f.text_field :robots %&gt;&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;tr&gt;&lt;td&gt;&lt;p&gt;&lt;label&gt;Page Order (number):&amp;nbsp;&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;%= f.text_field :page_order, :size=&gt;3 %&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;tr&gt;&lt;td&gt;&lt;p&gt;&lt;label&gt;Enable page&amp;nbsp;&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;%= f.check_box &#8220;showpage_flag&#8221; %&gt; &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;</p>
<p>&lt;/table&gt;</p>
<p><strong>3</strong> Open admin/pages_controller.rb</p>
<p><em>Add the following code into the controller:</em></p>
<p>def new</p>
<p style="padding-left:30px;">@page = Page.new</p>
<p>end</p>
<p>def edit</p>
<p style="padding-left:30px;"><span> </span>@page = Page.find(params[:id])</p>
<p>end</p>
<p>def show</p>
<p style="padding-left:30px;"><span> </span>@page = Page.find(params[:id])</p>
<p>end</p>
<p>def update</p>
<p style="padding-left:30px;">@page = Page.find(params[:id])</p>
<p style="padding-left:30px;">if @page.update_attributes(params[:page])</p>
<p style="padding-left:60px;">flash[:notice] = &#8220;Page was successfully updated.&#8221;</p>
<p style="padding-left:60px;">redirect_to admin_pages_path</p>
<p style="padding-left:30px;">else</p>
<p style="padding-left:60px;">flash[:notice] = &#8220;Page was not updated.&#8221;</p>
<p style="padding-left:60px;">render :action=&gt;&#8221;edit&#8221;</p>
<p style="padding-left:30px;">end</p>
<p>end</p>
<p>def create</p>
<p style="padding-left:30px;">@page = Page.new(params[:page])</p>
<p style="padding-left:30px;">if @page.save</p>
<p style="padding-left:60px;">flash[:notice] = &#8216;Page was successfully created.&#8217;</p>
<p style="padding-left:60px;">redirect_to admin_pages_path</p>
<p style="padding-left:30px;">else</p>
<p style="padding-left:60px;">flash[:notice] = &#8216;Page was not created.&#8217;</p>
<p style="padding-left:60px;">render :action=&gt;&#8221;new&#8221;</p>
<p style="padding-left:30px;">end</p>
<p>end</p>
<p>def destroy</p>
<p style="padding-left:30px;"><span> </span>Page.delete(params[:id])  <span> </span></p>
<p style="padding-left:30px;"><span> </span>@pages = Page.find(:all)<span> </span></p>
<p style="padding-left:30px;"><span> </span>render :action=&gt;&#8221;index&#8221;</p>
<p>end</p>
<p><strong>4</strong> create or add this file: app/views/admin/pages/show.html.erb</p>
<p><em>This is just a basic sample of how you could make a preview of some data. Add this code into the file:</em></p>
<p>&lt;div id=&#8221;wrapper&#8221;&gt;</p>
<p>&lt;div id=&#8221;content&#8221;&gt;</p>
<p>&lt;h1&gt;&lt;%= @page.title %&gt;&lt;/h1&gt;</p>
<p>&lt;p class=&#8221;text&#8221;&gt;</p>
<p>&lt;%= @page.content %&gt;&lt;br /&gt;</p>
<p>&lt;/p&gt;</p>
<p>&lt;/div&gt;</p>
<p>&lt;/div&gt;</p>
<p>Thats the end of this guide. I haven&#8217;t tested this to make sure it works. So if you find a bug in the code, let me know and I will update the blog entry. Now you should be able to Add, Edit, Delete and preview your data!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrewdegenhardt.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrewdegenhardt.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrewdegenhardt.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrewdegenhardt.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrewdegenhardt.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrewdegenhardt.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrewdegenhardt.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrewdegenhardt.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrewdegenhardt.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrewdegenhardt.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrewdegenhardt.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrewdegenhardt.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrewdegenhardt.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrewdegenhardt.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=63&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewdegenhardt.wordpress.com/2009/03/12/create-add-edit-and-show-pages-for-administrative-area-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">andrewdegenhardt</media:title>
		</media:content>
	</item>
		<item>
		<title>create a list of database items using Ruby on Rails, in the administrative area</title>
		<link>http://andrewdegenhardt.wordpress.com/2009/03/12/create-a-list-of-database-items-using-ruby-on-rails-in-the-administrative-area/</link>
		<comments>http://andrewdegenhardt.wordpress.com/2009/03/12/create-a-list-of-database-items-using-ruby-on-rails-in-the-administrative-area/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 07:07:15 +0000</pubDate>
		<dc:creator>andrewdegenhardt</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[add]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[administrative]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[def index]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[edit]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[step by step]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[view]]></category>

		<guid isPermaLink="false">http://andrewdegenhardt.wordpress.com/?p=58</guid>
		<description><![CDATA[This section shows how to make a list of items in Ruby on Rails, so that you can edit, delete, preview each item from the list.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=58&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This section shows how to make a list of items in Ruby on Rails, so that you can edit, delete, preview each item from the list. This view will also serve as the point where one can create a new Page, or whatever model you created in your project, Person, Game, Project, User, etc.</p>
<p><strong>1</strong> go into your controller file, for this blog I have been using Pages as the controller name:  app/controllers/admin/pages_controller.rb</p>
<p><strong>2</strong> find the &#8220;def index&#8221;, or create it with the following code:</p>
<p>def index</p>
<p style="padding-left:30px;">#use the first line for the public query</p>
<p style="padding-left:30px;">#@pages = Page.find(:all,:conditions=&gt; {:showpage_flag =&gt; true} , :order =&gt; &#8220;page_order DESC&#8221;)</p>
<p style="padding-left:30px;">@pages = Page.find(:all,:conditions=&gt; {:order =&gt; &#8220;page_order DESC&#8221;)</p>
<p>end</p>
<p><strong>3</strong> open or create this file: /app/views/admin/pages/index.html.erb</p>
<p><em>add the following code for a basic loop:</em></p>
<p><span> </span>&lt;%= link_to &#8220;New Page&#8221;, new_admin_page_path() %&gt;&amp;nbsp;&lt;br&gt;</p>
<p><span> </span>&lt;% @pages.each do |page| %&gt;</p>
<p><span> </span>&lt;%=link_to &#8220;Edit&#8221;, edit_admin_page_path(page) %&gt;&amp;nbsp;</p>
<p><span> </span>&lt;%=link_to &#8220;Delete&#8221;, admin_page_path(page), :confirm =&gt; &#8220;Are you sure you want to delete &#8221; + page.title + &#8220;?&#8221;, :method=&gt;:delete %&gt;&amp;nbsp;</p>
<p><span> </span>&lt;%=link_to &#8220;Preview&#8221;, admin_page_path(page) %&gt;&amp;nbsp;</p>
<p><span> </span>&lt;%= page.title %&gt; &lt;br&gt;</p>
<p><span> </span>&lt;% end %&gt;</p>
<p>Thats all, run http://localhost:3000/admin/pages/</p>
<p>you should see a &#8220;New Page&#8221; link</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrewdegenhardt.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrewdegenhardt.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrewdegenhardt.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrewdegenhardt.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrewdegenhardt.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrewdegenhardt.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrewdegenhardt.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrewdegenhardt.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrewdegenhardt.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrewdegenhardt.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrewdegenhardt.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrewdegenhardt.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrewdegenhardt.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrewdegenhardt.wordpress.com/58/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=58&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewdegenhardt.wordpress.com/2009/03/12/create-a-list-of-database-items-using-ruby-on-rails-in-the-administrative-area/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">andrewdegenhardt</media:title>
		</media:content>
	</item>
		<item>
		<title>create administrative area in ruby on rails</title>
		<link>http://andrewdegenhardt.wordpress.com/2009/03/10/create-administrative-area-in-ruby-on-rails/</link>
		<comments>http://andrewdegenhardt.wordpress.com/2009/03/10/create-administrative-area-in-ruby-on-rails/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 07:47:49 +0000</pubDate>
		<dc:creator>andrewdegenhardt</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[administrative]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[instructions]]></category>
		<category><![CDATA[layouts]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[routs.rb]]></category>
		<category><![CDATA[secure]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[step by step]]></category>

		<guid isPermaLink="false">http://andrewdegenhardt.wordpress.com/?p=48</guid>
		<description><![CDATA[This blog entry is for creating a space where you can have an administrative area. And you can also make it password secure.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=48&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This blog entry is for creating a space where you can have an administrative area, where your client can access it and add, edit, remove, etc. And you can also make it password secure, which i will show in another post.</p>
<p><a href="http://www.galaxypress.com/t.php?a=480124"><img src="http://www.galaxypress.com/affiliate/affiliate_images/pulpads/cowboy_freeoffer.jpg" border="0" width="410"></a></p>
<p><span style="font-size:small;"><strong><span style="font-family:Arial,Helvetica,sans-serif;color:#333333;"><br />
</span></strong></span></p>
<p>This will create the admin area, but you have to have a model created and migrated (create the database table for the model). You can make the model first, or do it after this. Find the blog entry on creating a Ruby on Rails project from Scratch, and in there it shows how to make a model and migrate it.</p>
<p>A migrated model can be accessed from a controller in the main namespace, or any other namespace. In this example below, it is the &#8220;admin&#8221; namespace.</p>
<p><strong>1 config/routes.rb</strong></p>
<p>map.namespace :admin do |admin|</p>
<p style="padding-left:30px;"><span> </span>admin.resources :pages</p>
<p>end</p>
<p><strong>2 run this in your project root, in terminal:</strong></p>
<p>script/generate controller admin/pages edit index new show</p>
<p><strong>3 add links in administrative main menu, and create the framework</strong></p>
<p>create the file views/layouts/admin.html.erb</p>
<p><em>This is your file for the  layout of the administrative area, its the framework that all your admin pages will use.</em></p>
<p>Put all this inside admin.html.erb:</p>
<p>&lt;html&gt;</p>
<p>&lt;head&gt;</p>
<p>&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=utf-8&#8243; /&gt;</p>
<p>&lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;/stylesheets/admin.css&#8221;&gt;</p>
<p>&lt;title&gt;Company Name::Administration&lt;/title&gt;</p>
<p>&lt;/head&gt;</p>
<p>&lt;body&gt;</p>
<p><span> </span>&lt;h1&gt;Company Name Administration&lt;/h1&gt;</p>
<p>&lt;a href=&#8221;/admin/pages&#8221;&gt;Pages&lt;/a&gt;</p>
<p>&amp;nbsp;|&amp;nbsp;&lt;a href=&#8221;/admin/another_controller&#8221;&gt;Another controller&lt;/a&gt;</p>
<p>&amp;nbsp;|&amp;nbsp;&lt;%= link_to &#8220;Log Out&#8221;, &#8220;/admin/users/show&#8221; %&gt;&lt;br&gt;</p>
<p>&lt;%=yield%&gt;</p>
<p>&lt;/body&gt;</p>
<p>&lt;/html&gt;</p>
<p><strong>4 add this line into the controller, at the top, in your app/controller/admin/pages_controller.rb:</strong></p>
<p>layout &#8220;admin&#8221;</p>
<p>Now you just need to create the model and do the migration. if you followed the blog entry on Creating a Ruby on Rails Project from Scratch, then this should be done already.</p>
<p>You should be able to run script/server and go to http://localhost:3000/admin/pages/</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>There will be another blog entry on the admin/users controller, which will show you how to make a log in screen and a starting point for administrative users.</p>
<p>Also there will be a blog entry to add the security to all the controllers in the admin namespace.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrewdegenhardt.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrewdegenhardt.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrewdegenhardt.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrewdegenhardt.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrewdegenhardt.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrewdegenhardt.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrewdegenhardt.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrewdegenhardt.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrewdegenhardt.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrewdegenhardt.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrewdegenhardt.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrewdegenhardt.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrewdegenhardt.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrewdegenhardt.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=48&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewdegenhardt.wordpress.com/2009/03/10/create-administrative-area-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">andrewdegenhardt</media:title>
		</media:content>

		<media:content url="http://www.galaxypress.com/affiliate/affiliate_images/pulpads/cowboy_freeoffer.jpg" medium="image" />
	</item>
		<item>
		<title>Setting up Ruby on Rails project from scratch</title>
		<link>http://andrewdegenhardt.wordpress.com/2009/03/05/setting-up-ruby-on-rails-project-from-scratch/</link>
		<comments>http://andrewdegenhardt.wordpress.com/2009/03/05/setting-up-ruby-on-rails-project-from-scratch/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 09:51:07 +0000</pubDate>
		<dc:creator>andrewdegenhardt</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[create table]]></category>
		<category><![CDATA[from scratch]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[migrate]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[remote git]]></category>
		<category><![CDATA[starting out]]></category>

		<guid isPermaLink="false">http://andrewdegenhardt.wordpress.com/?p=41</guid>
		<description><![CDATA[This quick start guide to setting up a Ruby on Rails project assumes that you successfully installed Ruby on Rails and GIT onto your computer, mac or linux. <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=41&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This blog entry is for starting a Ruby on Rails project from scratch.</p>
<p>This entry assumes that you successfully installed Ruby on Rails onto your computer, mac or linux. This is not for windows users, although it may work.</p>
<p>I don&#8217;t guarantee that this will work for everyone&#8217;s environ. There may be a couple points along the way that won&#8217;t make sense, won&#8217;t work, etc. This is just a guide to help the new guy or girl get started.</p>
<p><strong>1</strong> in your home directory run this:</p>
<p>rails -d sqlite3 ProjectName</p>
<p>*note: i prefer to call my apps rails-MyProject, so all my apps are in a group in my home directory</p>
<p><strong>2</strong> go into ~/ProjectName/ directory, then run:<span> </span></p>
<p>rake db:create</p>
<p>*Note: if you want to create a database model now, follow 3, 4, 5. otherwise, skip these three steps</p>
<p><strong>3</strong> in the same directory, run:</p>
<p>script/generate model Page</p>
<p><strong>4</strong> look into db/migrate/, there you will find a .rb file with a date timestamp, and the file should have the word Page in it.</p>
<p>edit the file as shown below, use :text for large blocks of text, :integer for numbers</p>
<p>class CreatePages &lt; ActiveRecord::Migration</p>
<p style="padding-left:30px;">def self.up</p>
<p style="padding-left:60px;">create_table :pages do |t|</p>
<p style="padding-left:90px;"># id is created for us.</p>
<p style="padding-left:90px;">
<p style="padding-left:90px;"><span> </span> t.column :title,   :string</p>
<p style="padding-left:90px;"><span> </span> t.column :content, :text</p>
<p style="padding-left:90px;"><span> </span> t.column :page_order,   :integer</p>
<p style="padding-left:90px;">t.column :shortname, :string</p>
<p style="padding-left:90px;">t.column :showpage_flag, :boolean, :default =&gt; true</p>
<p style="padding-left:90px;">t.column :tags, :text</p>
<p style="padding-left:90px;">t.column :description, :string</p>
<p style="padding-left:90px;">t.column :robots, :string</p>
<p style="padding-left:60px;">end</p>
<p style="padding-left:30px;">end</p>
<p style="padding-left:30px;">def self.down</p>
<p style="padding-left:60px;">drop_table :pages</p>
<p style="padding-left:30px;">end</p>
<p>end</p>
<p><strong>5</strong> in the project directory again, run:</p>
<p>rake db:migrate</p>
<p>check the schema file in the db/ directory to verify that your table was created.</p>
<p><strong>6</strong> then open config/database.yml in a text editor, edit as below:</p>
<p style="padding-left:30px;">
<p style="padding-left:30px;">development:</p>
<p style="padding-left:30px;">adapter: sqlite3</p>
<p style="padding-left:30px;">database: db/development.sqlite3</p>
<p style="padding-left:30px;">timeout: 5000</p>
<p style="padding-left:30px;">
<p style="padding-left:30px;">test:</p>
<p style="padding-left:30px;">adapter: sqlite3</p>
<p style="padding-left:30px;">database: db/test.sqlite3</p>
<p style="padding-left:30px;">timeout: 5000</p>
<p style="padding-left:30px;">#the following data you get from your Ruby on Rails provider for your remote production application.</p>
<p style="padding-left:30px;">production:</p>
<p style="padding-left:30px;">adapter: mysql</p>
<p style="padding-left:30px;">database:</p>
<p style="padding-left:30px;">username:</p>
<p style="padding-left:30px;">password:</p>
<p style="padding-left:30px;">encoding: utf8</p>
<p><strong>9</strong> add a .gitignore file into the root of the Project directory</p>
<p style="padding-left:30px;">
<p style="padding-left:30px;">log/*.log</p>
<p style="padding-left:30px;">tmp/**/*</p>
<p style="padding-left:30px;">doc/api</p>
<p style="padding-left:30px;">doc/app</p>
<p style="padding-left:30px;">db/*.sqlite3</p>
<p><strong>10 </strong>This is where you use git to move your project files to the remote server, and establish your local project branches. Git is pretty easy to set up. the tricky parts come when you start working with branches, merging, and pushing and pulling. Once you have git installed, you can easily follow the help files to initialize your git repository, and thus follow the step in this blog entry.</p>
<p>You need to set up git to push and pull your project; follow this if you have a Ruby on Rails provider or your own remote server, these instructions are for setting up git over ssh, you will need to generate ssh keys and send them to the remote administrator. For PROJECTNAME, use the name of the project as above. Your remote administrator can help you, I hope you have one.</p>
<p>open your .git/config file, modify as such:</p>
<p style="padding-left:30px;">[remote "origin"]</p>
<p style="padding-left:60px;"><span> </span>url = git@DomainNameOfProvider.com:PROJECTNAME.git</p>
<p style="padding-left:60px;"><span> </span>fetch = +refs/heads/*:refs/remotes/origin/*</p>
<p style="padding-left:30px;">
<p style="padding-left:30px;">[branch "master"]</p>
<p style="padding-left:60px;">remote = origin</p>
<p style="padding-left:60px;">merge = refs/heads/master</p>
<p style="padding-left:30px;">
<p><strong>11</strong> run these commands on your local computer:</p>
<p>git remote add origin git@DomainNameOfProvider.com:PROJECTNAME.git</p>
<p># you can now do some work locally with some of the files in the project, then you should:</p>
<p>git add *</p>
<p>git commit -a (you will be prompted to type in a log entry, so write-out then exit this screen, or if VIM is used, type an entry and then :wq)</p>
<p>then:</p>
<p>git push origin master:refs/heads/master</p>
<p>This should set up your rails project locally and remotely with GIT. the only point that you might have to get help on is point 10, where you should have an administrator on the remote end to help you set up the remote git project. I&#8217;ve done it another way remotely, but I will put those instructions in another blog entry. Ask your administrator for help.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/andrewdegenhardt.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andrewdegenhardt.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/andrewdegenhardt.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andrewdegenhardt.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/andrewdegenhardt.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andrewdegenhardt.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/andrewdegenhardt.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andrewdegenhardt.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/andrewdegenhardt.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andrewdegenhardt.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/andrewdegenhardt.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andrewdegenhardt.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/andrewdegenhardt.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andrewdegenhardt.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=andrewdegenhardt.wordpress.com&amp;blog=4817250&amp;post=41&amp;subd=andrewdegenhardt&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://andrewdegenhardt.wordpress.com/2009/03/05/setting-up-ruby-on-rails-project-from-scratch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">andrewdegenhardt</media:title>
		</media:content>
	</item>
	</channel>
</rss>
