<?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>Vision Master Designs &#187; Ruby on Rails</title>
	<atom:link href="http://visionmasterdesigns.com/category/wp/ror/feed/" rel="self" type="application/rss+xml" />
	<link>http://visionmasterdesigns.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 02 Aug 2010 12:09:29 +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>Tutorial : Introduction to AJAX in Ruby on Rails with Prototype, Script.aculo.us</title>
		<link>http://visionmasterdesigns.com/tutorial-introduction-to-ajax-in-ruby-on-rails-with-prototype-scriptaculous/</link>
		<comments>http://visionmasterdesigns.com/tutorial-introduction-to-ajax-in-ruby-on-rails-with-prototype-scriptaculous/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 16:40:43 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript Frameworks]]></category>
		<category><![CDATA[Prototype, Script.aculo.us]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[Script.aculo.us]]></category>

		<guid isPermaLink="false">http://www.visionmasterdesigns.com/?p=684</guid>
		<description><![CDATA[Heya, After a long time I had the time to update my blog. I have been working on my project presentation for the past 2 weeks. The entire presentation was developed in Flash CS3 coded in ActionScript 3. It was ages since I had used Flash and I was quite astonished how it had changed [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 0 0 0.6em 0.6em;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-introduction-to-ajax-in-ruby-on-rails-with-prototype-scriptaculous%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-introduction-to-ajax-in-ruby-on-rails-with-prototype-scriptaculous%2F&amp;source=rowoot&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Heya,<br />
After a long time I had the time to update my blog. I have been working on my project presentation for the past 2 weeks. The entire presentation was developed in Flash CS3 coded in ActionScript 3. It was ages since I had used Flash and I was quite astonished how it had changed over the years. I`ll be soon posting some tutorials on Flash, so do keep an eye out <img src='http://visionmasterdesigns.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Anyways apart from being a bit off-topic, This tutorial deals with AJAX implementation in Ruby on Rails 2. While I was learning RoR, I had lot of issues of properly having AJAX implementation in my projects. This tuorial is for those people out there.</p>
<p>In this tutorial, I`ll just show some very simple Script.aculo.us Animation Implementations in RoR.<br />
<a href="http://www.visionmasterdesigns.com:12001/ajaxfunction" target="_blank">View Demo</a></p>
<p><span id="more-684"></span></p>
<h2>Introduction</h2>
<p>First off, if you followed my RoR tutorials, you should know that RoR has AJAX support built in to it. It uses the Prototype Javascript Library along with Scriptaculous.</p>
<h2>Step 1 &#8211; Create new RoR Application</h2>
<p>First create a new RoR application. Edit the <span class="code">database.yml</span> file as well. If you are new to RoR, then visit <a href="http://www.visionmasterdesigns.com/2008/07/tutorial-developing-your-first-ruby-on-rails-2-application/">Tutorial : Developing your First Ruby on Rails 2 Application</a></p>
<h2>Step 2 &#8211; Create a Controller</h2>
<p>After creating the new application, we need to create a controller. lets call the controller <span class="code">ajaxfunctions</span>. I hope you guys know how to create a controller.</p>
<pre lang="ruby">    ruby script/generate controller ajaxfunctions index</pre>
<p>The above code will create a controller called <span class="code">ajaxfunctions</span> which will have a method called <span class="code">index</span>, respectively <span class="code">index.rhtml</span> OR <span class="code">index.html.erb</span> will be created inside the <strong>view/ajaxfunctions</strong> folder.</p>
<h2>Step 3 &#8211; Editing the view file</h2>
<p>Once you open it, you`ll notice that its empty. This is our template, basic HTML would suffice. So type out an html page here or you can use the one below.</p>
<pre class="brush: html">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Great. Now firstly, to implemenet AJAX in RoR , we need to initialize it.</p>
<h4>Initializing the Ajax code</h4>
<p>You must include the javascript code in your view template file (i.e index.rhtml in our case) for the Ajax functions to be available in that view. The best place for this is in the <span class="code">&lt;head&gt;</span> tag.</p>
<p>You can either use</p>
<ul>
<li><span class="code">&lt;%= javascript_include_tag  :defaults %&gt;</span><br />
We`ll be using this. Using this allows for quicker downloads since the script can be cached by the browsers.<br />
This is the output in the HTML page.</p>
<pre class="brush: html">
&lt;html&gt;
&lt;head&gt;
...
&lt;script src=&quot;/javascripts/prototype.js?1219423129&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/javascripts/effects.js?1219423129&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/javascripts/dragdrop.js?1219423129&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/javascripts/controls.js?1219423129&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;/javascripts/application.js?1219423129&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
...
&lt;/head&gt;
&lt;/html&gt;
</pre>
</li>
<li><span class="code">&lt;%= define_javascript_functions %&gt;</span><br />
This pastes all of the required Javascript code right into your view which increases your page size by ~20KB.</li>
</ul>
<h4>Different AJAX Helpers used in View Files</h4>
<p>RoR creates the AJAX code for you via helper codes. Firstly</p>
<p><em>Defination:</em><br />
<strong>What is a Helper</strong> ?<br />
<strong>Helpers</strong> (“view helpers”) are modules that provide methods which are automatically usable in your view. They provide shortcuts to commonly used display code and a way for you to keep the programming out of your views. The purpose of a helper is to simplify the view. It’s best if the view file (RHTML/RXML) is short and sweet, so you can see the structure of the output. Nitty-gritty details are best left to helper methods and partials, where they can be parametrized and used repeatedly.</p>
<p><span class="code"><strong>Note :</strong> We can call AJAX via 2 methods i.e 1) Using a button and 2) Normal Links. Then we can add the arguments through which we can achieve to have cool visual effects or perform serious AJAX operations. </span></p>
<p><strong>AJAX</strong> Helpers</p>
<ol>
<li><span class="code"><strong>button_to_function(button_value, *args, &amp;mp;block)</strong></span><br />
Returns a button that‘ll trigger a JavaScript function using the onclick handler. All of these go into the body tag of the view file. You can use the <span class="code">visual_effect</span> function to specify any visual effects</p>
<p><strong>Example : </strong><br />
This will show a button with the value &#8220;Greeting&#8221;, upon clicking will show a alert box with &#8220;Hello World!&#8221; inside.</p>
<pre lang="ruby">&lt;%=button_to_function "Greeting", "alert('Hello world!')" %&gt;</pre>
<p>This will display a button with value &#8220;Fade&#8221;, upon clicking will fade in or fade out the element &#8216;fade_text&#8217; (It can be a div element with id=fade_text).</p>
<pre lang="ruby">&lt;%=button_to_function "Fade", visual_effect(:toggle_appear, "fade_text", :duration =&gt; 0.5)%&gt;</pre>
</li>
<li><span class="code"><strong>link_to_function(name, *args, &amp;block) </strong></span><br />
Intead of a button, if you want to implement AJAX functionality using a text link. You can use this helper.<br />
Returns a link that will trigger a JavaScript function using the onclick handler and return false after the fact.</p>
<p><strong>Example : </strong><br />
This will show a &#8220;Greeting&#8221; link, upon clicking will show a alert box with &#8220;Hello World!&#8221; inside.</p>
<pre lang="ruby">&lt;%=link_to_function "Greeting", "alert('Hello world!')" %&gt;</pre>
<p>This will display a &#8220;Slide Me&#8221; link, upon clicking it will slide in or out the element &#8216;slide_text&#8217; (It can be a div element with id=slide_text).</p>
<pre lang="ruby">&lt;%=link_to_function "Slide Me", visual_effect(:toggle_slide, "slide_text", :duration =&gt; 0.5)%&gt;</pre>
</li>
<h4>Helper for Animation</h4>
<li><span class="code">visual_effect(name, element_id = false, js_options = {})</span><br />
Returns a JavaScript snippet to be used on the Ajax callbacks for starting visual effects.</p>
<p><strong>Example : </strong><br />
This will show a &#8220;Highlight&#8221; button, upon clicking will highlight the element which is specified.</p>
<pre lang="ruby">&lt;%=button_to_function "Highlight", visual_effect(:highlight, "element_id_name",:startcolor =&gt; '#ffff99', :endcolor =&gt; '#ffffff')%&gt;</pre>
<p>This will display a &#8220;Grow&#8221; link, upon clicking it will grow the specified element_id_name</p>
<pre lang="ruby">&lt;%= link_to_function "Grow", visual_effect(:grow,"element_id_name",:direction =&gt; "center",:duration =&gt; 1)%&gt;</pre>
</li>
</ol>
<p>I would really suggest to go through <a href="http://github.com/madrobby/scriptaculous/wikis">Script.aculo.us WIKI</a> to know more about every effect and their parameters. All of these effects can be used with RoR. For Example I have attached the code for the demo file.</p>
<h2>Code for the Demo File</h2>
<p><a href="http://www.visionmasterdesigns.com:12001/ajaxfunction" target="_blank">View Demo</a></p>
<pre class="brush: ruby">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;AJAX&lt;/title&gt;
&lt;%= javascript_include_tag  :defaults %&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;%=button_to_function &quot;Greeting Alert Me&quot;, &quot;alert(&#039;Hello world!&#039;)&quot; %&gt;&lt;br /&gt;&lt;br /&gt;
&lt;h4&gt;Actions with paragraph using buttons&lt;/h4&gt;
&lt;%=button_to_function &quot;Fade&quot;, visual_effect(:toggle_appear, &quot;fade&quot;, :duration =&gt; 0.5)%&gt;
&lt;%=button_to_function &quot;Slide&quot;, visual_effect(:toggle_slide, &quot;fade&quot;,:duration =&gt; 1)%&gt;
&lt;%=button_to_function &quot;Highlight&quot;, visual_effect(:highlight, &quot;fade&quot;,:startcolor =&gt; &#039;#ffff99&#039;, :endcolor =&gt; &#039;#ffffff&#039;)%&gt;

&lt;div id=&quot;fade&quot; style=&quot;border:1px solid #dbdbdb; margin:50px;&quot;&gt;
This is test, This is test&lt;br&gt;
This is testing....&lt;br&gt;
Lorum ipsum blablasadadada
&lt;/div&gt;

&lt;h4&gt;Actions with Green Box using links&lt;/h4&gt;
&lt;%= link_to_function &quot;Toggle Fade&quot;, visual_effect(:toggle_appear, &quot;s1&quot;, :duration =&gt; 0.5)%&gt; ||
&lt;!-- Transitions --&gt;&lt;%= link_to_function &quot;Fade with wobble&quot;,&quot;new Effect.Fade(&#039;s1&#039;, { transition: Effect.Transitions.wobble })&quot; %&gt; ||
&lt;!-- grow effect --&gt;&lt;%= link_to_function &quot;Grow&quot;, visual_effect(:grow,&quot;s1&quot;,:direction =&gt; &quot;center&quot;,:duration =&gt; 1)%&gt; ||
&lt;!-- shake effect --&gt;&lt;%= link_to_function &quot;Shake&quot;, visual_effect(:shake,&quot;s1&quot;,:distance =&gt; &quot;30&quot;,:duration =&gt; 1)%&gt; ||
&lt;!-- morph effect --&gt;&lt;%= link_to_function &quot;Morph to Red box&quot;, visual_effect(:morph,&quot;s1&quot;,:style =&gt; &quot;{background: &#039;#f00&#039;,color: &#039;#fff&#039;,width: &#039;200px&#039;}&quot; )%&gt; ||
&lt;br&gt;
&lt;br&gt;
&lt;div id=&quot;s1&quot; style=&quot;width:80px; height:80px; cursor:move; background:#88da5d; border:1px solid #444; text-align:center;&quot;&gt;
&lt;/div&gt;

&lt;h4&gt;Drag Action with Blue Box&lt;/h4&gt;
&lt;div id=&quot;s2&quot; style=&quot;width:80px; height:80px; cursor:move; background:#7baaed; border:1px solid #333; text-align:center;&quot;&gt;
&lt;%= draggable_element(&quot;s2&quot;, :revert =&gt; true) %&gt;
DRAG ME
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h4>Related Articles</h4>
<p><a href="http://www.visionmasterdesigns.com/2008/07/tutorial-installing-ruby-on-rails-2-in-windows-vista-xp/">Tutorial : Installing Ruby on Rails 2 in Windows Vista/XP</a><br />
<a href="http://www.visionmasterdesigns.com/2008/07/tutorial-developing-your-first-ruby-on-rails-2-application/">Tutorial : Developing your First Ruby on Rails 2 Application</a><br />
<a href="http://www.visionmasterdesigns.com/2008/08/tutorial-basics-ruby-on-rails-2-model-controller-view-routing/">Tutorial : Basics on Ruby on Rails 2 Model, Controller and Views and Routing</a><br />
<a href="http://www.visionmasterdesigns.com/2008/08/tutorial-create-blog-using-ruby-on-rails-2-relationship/">Tutorial : Create a blog using Ruby on Rails 2. (Part 1 &#8211; Relationships)</a><br />
<a href="http://www.visionmasterdesigns.com/2008/09/tutorial-create-a-login-system-in-ruby-on-rails/">Tutorial : Create a login system in Ruby on Rails</a></p>
]]></content:encoded>
			<wfw:commentRss>http://visionmasterdesigns.com/tutorial-introduction-to-ajax-in-ruby-on-rails-with-prototype-scriptaculous/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Tutorial : Create a login system in Ruby on Rails</title>
		<link>http://visionmasterdesigns.com/tutorial-create-a-login-system-in-ruby-on-rails/</link>
		<comments>http://visionmasterdesigns.com/tutorial-create-a-login-system-in-ruby-on-rails/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 11:10:57 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[Login System]]></category>

		<guid isPermaLink="false">http://www.visionmasterdesigns.com/?p=597</guid>
		<description><![CDATA[Hello everyone, In today&#8217;s tutorial I`ll teach you how to create a very basic Login System in Ruby on Rails. Welcome to Tutorial : Create a login system in Ruby on Rails. Before proceeding I would suggest you guys to read Tutorial : Create a blog using Ruby on Rails 2. (Part 1 &#8211; Relationships) [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 0 0 0.6em 0.6em;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-create-a-login-system-in-ruby-on-rails%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-create-a-login-system-in-ruby-on-rails%2F&amp;source=rowoot&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Hello everyone,<br />
In today&#8217;s tutorial I`ll teach you how to create a very basic Login System in <strong>Ruby on Rails</strong>. Welcome to <strong>Tutorial : Create a login system in Ruby on Rails</strong>. Before proceeding I would suggest you guys to read <a href="http://www.visionmasterdesigns.com/2008/08/tutorial-create-blog-using-ruby-on-rails-2-relationship/">Tutorial : Create a blog using Ruby on Rails 2. (Part 1 &#8211; Relationships)</a> since we will be using this sytem in our application.</p>
<h2>Introduction</h2>
<p>We will create a very simple standalone login system first, It will check the database for valid users. Then I`ll let you know how to integrate a similar login system in our blog application. First of course the basics.</p>
<p>We would need to design
<ul>
<li>Login page</li>
<li>A page which would have to be protected by the login system</li>
<li>Function to Check session, if not valid, then redirect to login page.</li>
</ul>
<p>Demo of the Login System in RoR : <a href="http://visionmasterdesigns.com:12001/user/login">Click Here</a> (user:admin,pass:admin)</p>
<p><span id="more-597"></span></p>
<h4>Step 1 : Create &#8216;logintest&#8217; Rails app</h4>
<p>Ok, Fire up the command prompt window, Lets create our Rails application called &#8216;<strong>logintest</strong>&#8216;.</p>
<pre lang="cmd">C:\railsappz>rails logintest -d mysql</pre>
<p>After creating the Rails application, you`ll notice a new directory called logintest being created. Navigate inside.</p>
<h4>Step 2 : Modify the &#8216;database.yml&#8217; &#038; Create Tables</h4>
<p>Since, our authentication system is going to check the backend for valid users, we need to tell it which database to refer, for the same you need to modify the <strong>database.yml</strong> file. By now, you must have known this procedure, but for those guys who don`t know how to, here is a lowdown. Navigate to <span class="code">C:\railsappz\login\config</span>, inside it you`ll find <strong>database.yml</strong></p>
<p>Open it, then modify the code inside. Please put a valid database name, a valid username and password (mysql). If you want to know how to create databases using phpMyAdmin, read here <a href="http://www.visionmasterdesigns.com/2008/07/tutorial-using-phpmyadmin-to-manage-mysql/">Tutorial : Using phpMyAdmin to manage mySQL</a></p>
<p>Secondly, we need to create the &#8216;User&#8217; Table. This table already has some user information.</p>
<pre class="brush: sql">
CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL auto_increment,
  `user_name` varchar(255) default NULL,
  `password` varchar(255) default NULL,
  `role` int(11) default NULL,
  `created_at` datetime default NULL,
  `updated_at` datetime default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

INSERT INTO `users` (`id`, `user_name`, `password`, `role`, `created_at`, `updated_at`) VALUES
(1, &#039;admin&#039;, &#039;admin&#039;, 0, NULL, NULL),
(2, &#039;test&#039;, &#039;test&#039;, 1, NULL, NULL);
</pre>
<p>These are the 2 entries we have entered in our User Table.</p>
<ol>
<li>
Username : admin<br />
Password : admin
</li>
<li>
Username : test<br />
password : test
</li>
</ol>
<p>The following is how MY database.yml looks.</p>
<pre class="brush: ruby">
development:
  adapter: mysql
  encoding: utf8
  database: login
  username: root
  password: root
  host: localhost

test:
  adapter: mysql
  encoding: utf8
  database: login
  username: root
  password: root
  host: localhost

production:
  adapter: mysql
  encoding: utf8
  database: login
  username: root
  password: root
  host: localhost
</pre>
<h4>Step 3 : Generate the &#8216;User&#8217; Model</h4>
<p>Creating a model is very important, because for any querying to the database, we need to use a object of this model, similarly to import the form values (login form), we will be using the object of User model.</p>
<p>So we need to tell our app about this mode. Since we are not using database, we`ll skip the database files that normally get created, while creating a model. We`ll use the <strong>&#8211;skip-migrations</strong> option.</p>
<pre lang="cmd">C:\railsappz\login>ruby script/generate model user --skip-migrations</pre>
<p>Lets move on to creating the User Controller.</p>
<h4>Step 4 : Generate the &#8216;User&#8217; Controller</h4>
<p>Now lets create our User Controller. Before creating, Lets do a check on what all we would require, cuz accordingly we have to create our controller.</p>
<ol>
<li>Login Page</li>
<li>Private Page</li>
</ol>
<p>So Our controller file will have the <strong>login page</strong>, <strong>private page</strong>.</p>
<pre lang="cmd">C:\railsappz\login>ruby script/generate controller user login private</pre>
<pre lang="cmd">
      exists  app/controllers/
      exists  app/helpers/
      create  app/views/user
      exists  test/functional/
      create  app/controllers/user_controller.rb
      create  test/functional/user_controller_test.rb
      create  app/helpers/user_helper.rb
      create  app/views/user/login.html.erb
      create  app/views/user/private.html.erb
</pre>
<p>If you noticed, you`ll see that whatever parameters we specified, view files with the same name are created, i.e login.html.erb, private.html.erb. Basically</p>
<p>Lets decipher the above code,</p>
<p><strong>User &#8211; Controller Name</strong><br />
Parameters :</p>
<ul>
<li><span class="code">login</span> &#8211; Creates a empty function inside <span class="code">user_controller.rb</span> and also creates a view file called <span class="code">login.html.erb</span> which will contain our Login Form.
</li>
<li>
<span class="code">private</span> &#8211; Creates a empty function inside <span class="code">user_controller.rb</span> and also creates a view file called <span class="code">private.html.erb</span> which will contain the content to be protected using our login system.
</li>
</ul>
<h4>Step 5 : Edit the Views, viz: login.html.erb, private.html.erb</h4>
<p>Navigate to C:\railsappz\login\app\views\user, open up <strong>login.html.erb</strong>. Time to create our form. We will be using the ruby helpers.</p>
<pre class="brush: ruby">
&lt;% if flash[:notice] %&gt;
&lt;div style=&quot;font-family:&#039;Trebuchet MS&#039;; color:#FF0000; font-size:14px;&quot;&gt;
&lt;%= flash[:notice] %&gt;
&lt;/div&gt;
&lt;% end %&gt;

&lt;!--creates form, exectues the authenticate method when the submit button is clicked--&gt;
&lt;%= form_tag :action=&gt;&#039;authenticate&#039; %&gt;
User name:
&lt;%= text_field(&quot;userform&quot;, &quot;user_name&quot;,:size=&gt;&quot;20&quot; ) %&gt;
Password:
&lt;%= password_field(&quot;userform&quot;, &quot;password&quot;,:size=&gt;&quot;20&quot; )
%&gt;
&lt;input type=&quot;submit&quot; value=&quot; LOGIN &quot; /&gt;
</pre>
<p>Save the file, now open up <strong>private.html.erb</strong>. This will be our protected page. If someone tries to view this page directly he should be redirected to the login page. Only valid users should be able to see this page.</p>
<pre class="brush: ruby">
&lt;!--#displays hello (username)--&gt;
hello &lt;strong&gt;&lt;%=session[:user_id]%&gt;&lt;/strong&gt;.

&lt;!--#creates logout link, when the link is clicked, the controller is User and the method executed will be logout.--&gt;
&lt;%= link_to &quot;logout&quot;,:controller =&gt; &quot;user&quot;, :action =&gt; &quot;logout&quot; %&gt;
</pre>
<p>Ok, Now we have defined our view files and used some methods inside them, now its time to define these methods. All methods go inside the controller.</p>
<h4>Step 6 : Edit the user_controller.rb</h4>
<p>Navigate <span class="code">C:\railsappz\login\app\controllers</span> and open <strong>user_controller.rb</strong>. You will notice 2 empty methods viz login, private. Let them be the way they are for now, We will be creating 2 methods, first lets create a method to handle our authentication viz <strong>authenticate</strong>.</p>
<pre class="brush: ruby">
def authenticate
		#User.new(params[:userform]) will create a new object of User, retrieve values from the form and store it variable @user.
		@user = User.new(params[:userform])
        #find records with username,password
		valid_user = User.find(:first,:conditions =&gt; [&quot;user_name = ? and password = ?&quot;,@user.user_name, @user.password])

        #if statement checks whether valid_user exists or not
		if valid_user
        #creates a session with username
			session[:user_id]=valid_user.user_name
        #redirects the user to our private page.
			redirect_to :action =&gt; &#039;private&#039;
		else
			flash[:notice] = &quot;Invalid User/Password&quot;
			redirect_to :action=&gt; &#039;login&#039;
		end
end
</pre>
<p>Second method is for to handle the logout. When the logout link will be clicked, this method will be called. As you can see, we will reset the session created during authenticate method and redirect the user to the login page again.</p>
<pre class="brush: ruby">
  def logout
	  if session[:user_id]
		  reset_session
		  redirect_to :action=&gt; &#039;login&#039;
	  end
  end
</pre>
<p>Now to test the server. Run <span class="code">ruby script/server</span>. You will see the usual Riding on Rails Page.<br />
Point your browser to <a href="http://myserver.dev:3000/user/login">http://myserver.dev:3000/user/login</a> to see the login page. </p>
<p>If you have followed all the steps properly, you`ll see that the login system is working fine, except for a lil important modifications.</p>
<p>First logout, then Try pointing your browser to <a href="http://myserver.dev:3000/user/private">http://myserver.dev:3000/user/private</a>, you`ll notice that you are able to view the private page !!!<br />
Lets rectify this problem</p>
<h4>Step 7 : Modify the private method in user_controller.rb</h4>
<p>Since we just have to protect one page, we can simply use an if statement to check the session and respectively allow or disallow them to view the private page. Remember we had created a private method in user_controller.rb (Our User Controller). So your new private method will look like the following</p>
<pre class="brush: ruby">
  def private
 	 if !session[:user_id]
    	redirect_to :action=&gt; &#039;login&#039;
	end
  end
</pre>
<p>Voila ! We have secured our private page. Finally</p>
<p>This is how your final <strong>User_controller.rb</strong> should look</p>
<pre class="brush: ruby">
class UserController &lt; ApplicationController
def authenticate
		#User.new(params[:userform]) will create a new object of User, retrieve values from the form and store it variable @user.
		@user = User.new(params[:userform])
        #find records with username,password
		valid_user = User.find(:first,:conditions =&gt; [&quot;user_name = ? and password = ?&quot;,@user.user_name, @user.password])

        #if statement checks whether valid_user exists or not
		if valid_user
        #creates a session with username
			session[:user_id]=valid_user.user_name
        #redirects the user to our private page.
			redirect_to :action =&gt; &#039;private&#039;
		else
			flash[:notice] = &quot;Invalid User/Password&quot;
			redirect_to :action=&gt; &#039;login&#039;
		end
end

  def login
  end

  def private
  if !session[:user_id]
	redirect_to :action=&gt; &#039;login&#039;
	end
  end

  def logout
	  if session[:user_id]
		  reset_session
		  redirect_to :action=&gt; &#039;login&#039;
	  end
  end

end
</pre>
<p>Now to test the server again, Re-Run <span class="code">ruby script/server</span>.<br />
Try pointing your browser to <a href="http://myserver.dev:3000/user/private">http://myserver.dev:3000/user/private</a>, you will see that you will be redirected to the login page (if you previously logged out, else if the session is still valid, you`ll see the private page).</p>
<p>Phew&#8230;  Well thats about how to design the Login System in Ruby on Rails. If you guys have any problems, as usual you can always post a comment here. I`ll be posting another post on how to integrate this login system in our blog application.</p>
<p>Demo of the Login System in RoR : <a href="http://visionmasterdesigns.com:12001/user/login">Click Here</a> (user:admin,pass:admin)</p>
<h2>Related Links</h2>
<p><a href="http://www.visionmasterdesigns.com/2008/08/tutorial-create-blog-using-ruby-on-rails-2-relationship/">Tutorial : Create a blog using Ruby on Rails 2. (Part 1 &#8211; Relationships)</a><br />
<a href="http://www.visionmasterdesigns.com/2008/08/tutorial-basics-ruby-on-rails-2-model-controller-view-routing/">Tutorial : Basics on Ruby on Rails 2 Model, Controller and Views and Routing</a><br />
<a href="http://www.visionmasterdesigns.com/2008/07/tutorial-developing-your-first-ruby-on-rails-2-application/">Tutorial : Developing your First Ruby on Rails 2 Application</a><br />
<a href="http://www.visionmasterdesigns.com/2008/07/tutorial-installing-ruby-on-rails-2-in-windows-vista-xp/">Tutorial : Installing Ruby on Rails 2 in Windows Vista/XP</a></p>
<div class="donate"><strong>Buy me a beer.</strong></p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="rowoot@gmail.com">
<input type="hidden" name="item_name" value="MICHEAL BENEDICT ARUL">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="tax" value="0">
<input type="hidden" name="lc" value="IN">
<input type="hidden" name="bn" value="PP-DonationsBF">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"><br />
</form>
</div>
]]></content:encoded>
			<wfw:commentRss>http://visionmasterdesigns.com/tutorial-create-a-login-system-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Tutorial : Create a blog using Ruby on Rails 2. (Part 1 &#8211; Relationships)</title>
		<link>http://visionmasterdesigns.com/tutorial-create-blog-using-ruby-on-rails-2-relationship/</link>
		<comments>http://visionmasterdesigns.com/tutorial-create-blog-using-ruby-on-rails-2-relationship/#comments</comments>
		<pubDate>Sun, 24 Aug 2008 09:06:16 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[blog]]></category>

		<guid isPermaLink="false">http://www.visionmasterdesigns.com/?p=448</guid>
		<description><![CDATA[Hello ! Its been a long time since my last post. I have been hell busy this week, barely had time to update. This is the revised version. This tutorial will form the base for the upcoming series of tutorials on how to create a simple blog application in Ruby on Rails(RoR). Part 1 will [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 0 0 0.6em 0.6em;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-create-blog-using-ruby-on-rails-2-relationship%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-create-blog-using-ruby-on-rails-2-relationship%2F&amp;source=rowoot&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Hello !<br />
Its been a long time since my last post. I have been hell busy this week, barely had time to update. This is the <strong>revised version</strong>.</p>
<p>This tutorial will form the base for the upcoming series of tutorials on how to create a simple blog application in <strong>Ruby on Rails(RoR)</strong>.<br />
Part 1 will discuss about how relationships are defined in RoR and the basics as usual <img src='http://visionmasterdesigns.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h2>Index</h2>
<ul>
<li>Page 1 : <a title="Introduction" href="http://www.visionmasterdesigns.com/2008/08/tutorial-create-blog-using-ruby-on-rails-2-relationship/">Introduction</a></li>
<li>Page 2 : <a title="Create base application" href="http://www.visionmasterdesigns.com/2008/08/tutorial-create-blog-using-ruby-on-rails-2-relationship/2/">Create Scaffolds application</a></li>
<li>Page 3 : <a title="Relationships in RoR" href="http://www.visionmasterdesigns.com/2008/08/tutorial-create-blog-using-ruby-on-rails-2-relationship/3/">Modifying the Model,Controller and View</a></li>
</ul>
<p><span id="more-448"></span></p>
<h2>Introduction</h2>
<p>Let me explain what we are trying to create. We will be creating our own very simple blog application using Ruby on Rails.  The blog will have</p>
<ul>
<li>A Simple Login System</li>
<li>A Simple Administrative Interface to manage posts,categories and comments</li>
<li>Display comments for every post</li>
<li>Ajax Implementation</li>
</ul>
<p>What all you`ll learn :</p>
<ul>
<li>To create and work with scaffolds</li>
<li>Relationships in Rails</li>
<li>Migrations</li>
<li>How Models, Controllers and Views work</li>
<li>A simple login system</li>
<li>Ajax Implementation in this blog</li>
</ul>
<p><em>A lot more as we go on &#8230; <img src='http://visionmasterdesigns.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </em></p>
<h4>Some Conventions in Rails</h4>
<ul>
<li>
The name of the table must be in its plural form: By default everytime we create a scaffold, the table created will be of its pluralized form. Rails will derive the singular name for the corresponding class automatically.<br />
For Example. If we create a scaffold called <strong>category</strong>, Rails will automatically derive its plural form i.e <strong>categories</strong>.
</li>
<li>
By default primary key called id will be created for every scaffold even if not specified. The Data type of the Primary key should be Integer.
</li>
<li>
The Foreign keys should be named &#8216;table name of the referenced table + _id&#8217;<br />
For Example : if we want to use Table-Category&#8217;s Primary key &#8216;id&#8217;, we`ll create a attribute called <strong>category_id</strong> in our &#8216;posts&#8217; table.
</li>
</ul>
<h4>What are we doing in Part 1 ?</h4>
<p>In this tutorial (Part 1 of the Series) we`ll learn how to create different categories and assign our posts to these categories. Every post will show which category it belongs to.</p>
<p>So to achieve this, we need 2 tables. The database schema for the same will be something like</p>
<pre lang='sql'>
category(id,category_name)
post(id,post_title,post_text,date_of_creation,category_id)
</pre>
<p>The schema is pretty self explainatory. <span class="code">category_id</span> of &#8216;post&#8217; is the attribute which will contain the <span class="code">id</span> of &#8216;category&#8217;. The simplest way to put this is, every record inside the post table will contain <span class="code">category_id</span> which will help us retrieve the <span class="code">category_name</span> by referring to the other table i.e category.</p>
<p><strong>Pre-requistes :</strong></p>
<p>I would really suggest you people to read the following tutorials, to understand the basic of RoR.</p>
<ul>
<li>Please have a developer environment set up. For more information on how to set it up, read<br />
<a href="http://www.visionmasterdesigns.com/2008/07/tutorial-installing-ruby-on-rails-2-in-windows-vista-xp/">Tutorial : Installing Ruby on Rails 2 in Windows Vista/XP</a></li>
<li>
<a href="http://www.visionmasterdesigns.com/2008/07/tutorial-developing-your-first-ruby-on-rails-2-application/">Tutorial : Developing your First Ruby on Rails 2 Application</a></li>
<li>
<a href="http://www.visionmasterdesigns.com/2008/08/tutorial-basics-ruby-on-rails-2-model-controller-view-routing/">Tutorial : Basics on Ruby on Rails 2 Model, Controller and Views and Routing</a>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://visionmasterdesigns.com/tutorial-create-blog-using-ruby-on-rails-2-relationship/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Tutorial : Basics on Ruby on Rails 2 Model, Controller and Views and Routing</title>
		<link>http://visionmasterdesigns.com/tutorial-basics-ruby-on-rails-2-model-controller-view-routing/</link>
		<comments>http://visionmasterdesigns.com/tutorial-basics-ruby-on-rails-2-model-controller-view-routing/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 05:24:28 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Programming]]></category>

		<guid isPermaLink="false">http://www.visionmasterdesigns.com/?p=375</guid>
		<description><![CDATA[Hey Guys, Finally I got 2 days off from my college *yay*. Now there will be lots of updates. Anyways, You must have noticed the new &#8220;Featured Flash Widget&#8221; and some small changes here and there, the site is being updated constantly with a lil tweaks here and there, so please bear with it. Today [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 0 0 0.6em 0.6em;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-basics-ruby-on-rails-2-model-controller-view-routing%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-basics-ruby-on-rails-2-model-controller-view-routing%2F&amp;source=rowoot&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Hey Guys,</p>
<p>Finally I got 2 days off from my college *yay*. Now there will be lots of updates. Anyways, You must have noticed the new &#8220;Featured Flash Widget&#8221; and some small changes here and there, the site is being updated constantly with a lil tweaks here and there, so please bear with it. Today I`ll show you how to create a simple &#8220;Hello World&#8221; application in RoR2. When I was trying to learn RoR2, there were no articles on how to create a simple &#8220;Hello World&#8221; application. So I thought I`ll take this time to introduce all the newbies to Ruby on Rails 2 on how to create a simple Hello World App.</p>
<p>If you don`t know how to install RoR2 in your system and want more information about Ruby on Rails 2, do read this tutorial<br />
<a style="padding-top: 0pt; padding-bottom: 0pt;" title="Tutorial : Installing Ruby on Rails 2 in Windows Vista/XP" href="http://www.visionmasterdesigns.com/2008/07/tutorial-installing-ruby-on-rails-2-in-windows-vista-xp/">Tutorial : Installing Ruby on Rails 2 in Windows Vista/XP  (4.75 out of 5)</a></p>
<h2>Index</h2>
<ul>
<li>Introduction</li>
<li><a href="http://www.visionmasterdesigns.com/2008/08/tutorial-basics-ruby-on-rails-2-model-controller-view-routing/2/">Basics of Ruby</a></li>
<li><a href="http://www.visionmasterdesigns.com/2008/08/tutorial-basics-ruby-on-rails-2-model-controller-view-routing/3/">Create helloworld rails application</a></li>
<li><a href="http://www.visionmasterdesigns.com/2008/08/tutorial-basics-ruby-on-rails-2-model-controller-view-routing/4/">Ruby on Rails 2 Routing</a></li>
</ul>
<p><span id="more-375"></span></p>
]]></content:encoded>
			<wfw:commentRss>http://visionmasterdesigns.com/tutorial-basics-ruby-on-rails-2-model-controller-view-routing/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Tutorial : Developing your First Ruby on Rails 2 Application</title>
		<link>http://visionmasterdesigns.com/tutorial-developing-your-first-ruby-on-rails-2-application/</link>
		<comments>http://visionmasterdesigns.com/tutorial-developing-your-first-ruby-on-rails-2-application/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 19:30:44 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://blog.visionmasterdesigns.com/?p=39</guid>
		<description><![CDATA[So, you have setup a RoR environment on your computer but don`t know where to start. Click here to learn to create your first application using RoR.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 0 0 0.6em 0.6em;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-developing-your-first-ruby-on-rails-2-application%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-developing-your-first-ruby-on-rails-2-application%2F&amp;source=rowoot&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><!-- 20/8/2008 !--><br />
So, you want to make an application using Ruby on Rails (RoR) huh ! Well, Lets try to make a simple &#8220;Article System&#8221;. Ruby on Rails is very easy at the same time a lil complicated. If you want to know more theory about Ruby on Rails, you can visit its official homepage <a href="http://www.rubyonrails.org">http://www.rubyonrails.org</a>. If you want a small summary of what it is, you can read my previous post <a href="http://www.visionmasterdesigns.com/2008/07/tutorial-installing-ruby-on-rails-2-in-windows-vista-xp/">Tutorial : Installing Ruby on Rails in Windows Vista/XP</a>.</p>
<p>Like I said in my previous post, RoR uses the MVC Architecture. (M-Model, V-Views, C-Controller)</p>
<p><a title="MVC Patter" rel="lightbox[pics39]" href="http://www.visionmasterdesigns.com/blog/wp-content/uploads/2008/07/t3a.jpg"><img class="attachment wp-att-40 centered" src="http://www.visionmasterdesigns.com/blog/wp-content/uploads/2008/07/t3a.thumbnail.jpg" alt="MVC Patter" width="450" height="337" /></a></p>
<p><span id="more-39"></span></p>
<p>The below diagram must be self-explainatory, but if it is not, then<br />
<strong>Models</strong> &#8211; Models communicate with the database, to retrieve the data and keep.<br />
<strong>Controller</strong> &#8211; Any requests made by the browser are forwarded to the Controller by the View, which refers the Models and modifies it in different ways (methods written in the Controller) and returns the results to View.<br />
<strong>View</strong> &#8211; This communicates with the browser, takes the inputs and forwards it to the Controller for the respective action, and the returned result from the Controller is forwarded by the view back to the browser.</p>
<p>Anyways, that was about MVC. So in RoR we always have to create these files for different functions.<br />
For our Article System, our objective is to create a system in RoR</p>
<ol>
<li>Create Database &#8216;articlesystem_development&#8217;</li>
<li>Take Article input from User</li>
<li>Display All the Article</li>
<li>Edit Article</li>
<li>Delete Article</li>
</ol>
<p>If we were to use PHP, this system would take not less than 50 Lines of Code, but in RoR &#8230;. you`ll soon find out;)</p>
<ol>
<li>Firstly open up Command Prompt (Start->Run) type cmd and click OK, then lets navigate to our ruby folder and create our application.<br />
The Syntax to create a new application is</p>
<pre class="brush: ruby">rails -d mysql appname</pre>
<p>So type</p>
<pre class="brush: ruby">C:\ruby\bin\&gt;rails -d mysql articlesystem</pre>
<p>A long list of files &amp; directories are created.</li>
<li>Before editing, Create a database articlesystem_development through phpmyAdmin. If you don`t know how to create a database then refer to <a href="http://www.visionmasterdesigns.com/blog/2008/07/tutorial-creating-a-content-management-system-using-phpmysql/2">Tutorial : Creating a Content Management System using PHP/MySQL</a> else you can use the mysql command to create the database.
<ol>
<li>Goto Start->Run. Type cmd and hit Enter. You will be prompted with the command prompt.</li>
<li>type <span class="code">mysql -u username -p</span>, hit enter</li>
<li>It`ll prompt you for your password. Enter the password.</li>
<li>Once your inside the console type CREATE DATABASE databasename \g i.e <span class="code">mysql>CREATE DATABASE databasename \g</span></li>
<li>If you see the following then you have successfully created a database.
<pre class="brush: sql">
mysql&gt; create database boo \g
Query OK, 1 row affected (0.00 sec)
</pre>
</li>
</ol>
</li>
<li>Good ! Now navigate to <strong>F:\server\ruby\bin\articlesystem\config</strong> and open the file <strong>&#8216;database.yml&#8217;</strong> in wordpad.
<pre class="brush: ruby">
development:
adapter: mysql
encoding: utf8
database: databasename
username: username
password: password
host: localhost

test:
adapter: mysql
encoding: utf8
database: databasename
username: username
password: password
host: localhost

production:
adapter: mysql
encoding: utf8
database: databasename
username: username
password: password
host: localhost
</pre>
<p>You will see the following,except the password area has not been edited yet so type in your mysql user password. (If you have followed the previous tutorial, then password is <strong>root</strong>), and please enter the same database name in all development,test and production.</li>
<li>Save the file.</li>
<li>Now comes the fun part. Open up Command Prompt. Now we need to create the tables for our database.<br />
Our database schema is</p>
<p>id(int)     title(string)     article(text)<br />
1            test article      bla bla bla.. lot of content</p>
<p>The above post was just an example, so basically we have 3 attributes i.e id, title and article.</li>
<li>We will be using rails &#8220;Scaffolding&#8221; feature to create these tables and link it with our system. Scaffolding as the name says, to clean the windows of a high rise building, scaffolding is used as support temporarily, similarly here we are going to use &#8216;scaffold&#8217; to generate links &amp; code.</li>
<li>Now type in
<pre class="brush: ruby">
c:\ruby\bin\articlesystem&gt;ruby script/generate scaffold article title:string article:text
</pre>
<p>You`ll see notice that rails creates another bunch of files
<pre class="brush: ruby">
C:\ruby\bin\articlesystem&gt;ruby script/generate scaffold article title:string article:text
exists  app/models/
exists  app/controllers/
exists  app/helpers/
create  app/views/articles
exists  app/views/layouts/
exists  test/functional/
exists  test/unit/
exists  public/stylesheets/
create  app/views/articles/index.html.erb
create  app/views/articles/show.html.erb
create  app/views/articles/new.html.erb
create  app/views/articles/edit.html.erb
create  app/views/layouts/articles.html.erb
create  public/stylesheets/scaffold.css
create  app/controllers/articles_controller.rb
create  test/functional/articles_controller_test.rb
create  app/helpers/articles_helper.rb
route  map.resources :articles
dependency  model
exists    app/models/
exists    test/unit/
exists    test/fixtures/
create    app/models/article.rb
create    test/unit/article_test.rb
create    test/fixtures/articles.yml
create    db/migrate
create    db/migrate/20080709183936_create_articles.rb
C:\ruby\bin\articlesystem&gt;
</pre>
</li>
<li>I know, there are hell lot of files being created !! <img src='http://visionmasterdesigns.com/wordpress/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  Anyways, I`ll just tell you what RoR has generated, it has managed to create
<ul>
<li><span class="code">article.rb</span> -> Model inside c:\ruby\bin\articlesystem\app\models\,</li>
<li><span class="code">articles_controller.rb</span> -> Controller (Which has methods of all the functions i.e Create,delete,showall,edit) inside c:\ruby\bin\articlesystem\app\controllers</li>
<li><span class="code">index.html.erb, edit.html.erb, new.html.erb, show.html.erb</span> -> View Files (More like templates which determine the looks of the site) inside C:\ruby\bin\articlesystem\app\views\articles</li>
</ul>
<p>Remember MVC &#8230; you can check the code out. But don`t modify any right now.</li>
<li>Now all you have to do is create the tables of the database. Hold on your horses, no need of logging in to mysql to create your tables. Just type this code
<pre class="brush: ruby">C:\ruby\bin\articlesystem&gt;rake db:migrate</pre>
</li>
<li>rake db:migrate -> executes the database schema RoR had generated automatically,<br />
Not only did RoR generate so many files, It also generated the table schema for articles.</p>
<pre class="brush: ruby">
# This file is auto-generated from the current state of the database. Instead of editing this file,
# please use the migrations feature of Active Record to incrementally modify your database, and
# then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
# to create the application database on another system, you should be using db:schema:load, not running
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you&#039;ll amass, the slower it&#039;ll run and the greater likelihood for issues).
#
# It&#039;s strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version =&gt; 20080709183936) do

create_table &quot;articles&quot;, :force =&gt; true do |t|
t.string   &quot;title&quot;
t.text     &quot;article&quot;
t.datetime &quot;created_at&quot;
t.datetime &quot;updated_at&quot;
end

end
</pre>
</li>
<li>Voila !!! RoR has just created all the necessary tables for you in mysql. Don`t believe me ? go check your database. Don`t be amazed, thats nothing, now time to test our code, invoke the ruby web server
<pre class="brush: ruby">C:\ruby\bin\articlesystem&gt;ruby script/server</pre>
</li>
<li>Point your web browser to <a href="http://localhost:3000/articles" target="_blank">http://localhost:3000/articles</a>
<p style="text-align: center;"><a title="Output" rel="lightbox[pics39]" href="http://www.visionmasterdesigns.com/blog/wp-content/uploads/2008/07/t3c.jpg"><img class="attachment wp-att-42 centered" src="http://www.visionmasterdesigns.com/blog/wp-content/uploads/2008/07/t3c.thumbnail.jpg" alt="Output" width="450" height="324" /></a></p>
</li>
<li>Congratulations !!! you have developed your first application in Ruby on Rails 2. Play around with the application, see what all you can do. RoR by default creates the delete,edit,create,show functions for your application when using &#8220;scaffold&#8221;. You can add articles, delete em, edit em or view all of em, from just 3 lines of code <img src='http://visionmasterdesigns.com/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
</ol>
<p>This is the power of RoR !! Although I wrote a very basic tutorial (since I had less time), this tutorial covers a little theory of RoR&#8217;s architecture, how to create an application using rails in development mode, how to create a scaffold and finally to rebuild the database using rake db:migrate.</p>
<p>So I hope you had fun, you can modify the view files in C:\ruby\bin\articlesystem\app\views\articles if you want to change the look of it.</p>
<p>You can make the application start directly from http://localhost:3000/ I`ll be showing that, in my next tutorial for RoR which includes basic link routing, some more extra features to our article system. In the next tutorial I`ll also discuss about the singular &amp; plural concepts in RoR which are very important. Till then Chow !</p>
<div class="donate">Found this tutorial really useful, you can click here to donate.</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input name="cmd" type="hidden" value="_donations" />
<input name="business" type="hidden" value="rowoot@gmail.com" />
<input name="item_name" type="hidden" value="MICHEAL BENEDICT ARUL" />
<input name="no_shipping" type="hidden" value="0" />
<input name="no_note" type="hidden" value="1" />
<input name="currency_code" type="hidden" value="USD" />
<input name="tax" type="hidden" value="0" />
<input name="lc" type="hidden" value="IN" />
<input name="bn" type="hidden" value="PP-DonationsBF" />
<input alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif" type="image" />
<img src="https://www.paypal.com/en_US/i/scr/pixel.gif" border="0" alt="" width="1" height="1" /><br />
</form>
</div>
]]></content:encoded>
			<wfw:commentRss>http://visionmasterdesigns.com/tutorial-developing-your-first-ruby-on-rails-2-application/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Tutorial : Installing Ruby on Rails 2 in Windows Vista/XP</title>
		<link>http://visionmasterdesigns.com/tutorial-installing-ruby-on-rails-2-in-windows-vista-xp/</link>
		<comments>http://visionmasterdesigns.com/tutorial-installing-ruby-on-rails-2-in-windows-vista-xp/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 12:09:19 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Vista]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[XP]]></category>

		<guid isPermaLink="false">http://blog.visionmasterdesigns.com/?p=35</guid>
		<description><![CDATA[Ruby on Rails is the next "in" thing. This tutorial teaches you step by step to set up Ruby on Rails environment on your local Computer.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin: 0 0 0.6em 0.6em;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-installing-ruby-on-rails-2-in-windows-vista-xp%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fvisionmasterdesigns.com%2Ftutorial-installing-ruby-on-rails-2-in-windows-vista-xp%2F&amp;source=rowoot&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p style="text-align: justify;">Greetings,</p>
<p style="text-align: justify;">Most of you must have heard of <span style="color: #000000;"><strong>&#8220;Ruby on Rails (RoR)&#8221;</strong></span>. It being touted as the next best thing (apart from php <img src='http://visionmasterdesigns.com/wordpress/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ). Well lemme give you a lowdown of what Ruby on Rails is&#8230;</p>
<p style="text-align: justify;">I`ll try to explain the power of RoR in the simplest of words,</p>
<p>If PHP can do something after typing <strong>75</strong> lines of code, RoR can do the same thing in typing mearly <strong>3</strong> lines of code !!!!<br />
Thats as simple is it gets ! But then again, there is a catch to it, RoR is equally complex. So Today, I`ll just give you the basic idea of what Ruby on Rails is, and how to set up a developer environment for RoR, So next time we can directly start creating applications. woohoo !<br />
<span id="more-35"></span></p>
<p style="text-align: justify;">But Firstly the basics.<br />
If you are aware of the basics then <a href="#down">Click Here</a> to jump below, else read on.</p>
<p style="text-align: justify;">&#8220;<strong><span style="color: #000000;">Ruby</span></strong> is a dynamic, reflective, general purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby was initially developed and designed by Yukihiro &#8220;Matz&#8221; Matsumoto.&#8221;</p>
<ul style="text-align: justify;">
<li> Ruby is very similar to our native object-oriented programming languages (eg: C++,Java).</li>
<li>You can define variables using &#8216;@&#8217; symbol.</li>
<li>You can define functions, more commonly known as methods using
<pre lang="ruby">def method_name
....
end</pre>
</li>
</ul>
<p style="text-align: justify;">&#8220;<strong>Ruby on Rails</strong> is framework developed particularly for web applications. The framework is coded using Ruby. It basically makes our lives easier by generating code automatically on execution of a single piece of code.</p>
<ul style="text-align: justify;">
<li>It uses the MVC Architecture. (Model-View-Controller, I`ll be explainin this in the next tutorial, which will be &#8216;Creating Your First RoR Application&#8217;)</li>
</ul>
<p style="text-align: justify;">I like to tell you that, its not easy deploying a RoR application (Thats right, its an application, not a script or a piece of code, but a combination of lots of directories &amp; files).<br />
Its not anything like the php scripts we upload to the server and run the script by pointing to the right address, there are various modes on how a RoR application is executed (Eg. developer, test, production).</p>
<p>Enough of the technical mumbo-jumbo, lets get down business.<a id="down" name="down"></a></p>
<p style="text-align: justify;">Pre-Requisites :</p>
<ol style="text-align: justify;">
<li>Webserver + MySQL installed</li>
<li><span style="color: #000000;"><strong>Ruby (1.8.6)</strong></span> : We need to install the basic ruby binaries and extensions to execute RoR applications.<br />
Download <a title="ruby186-26.exe" href="http://rubyforge.org/frs/download.php/29263/ruby186-26.exe">ruby186-26.exe</a></li>
</ol>
<p style="text-align: justify;">Basically you must have a normal php/mysql developer environment already installed, if not, you can refer to my earlier tutorial i.e<br />
<a href="http://www.visionmasterdesigns.com/blog/2008/07/tutorial-installing-apache-php-5-mysql-5-phpmyadmin-windows-vista-xp/">Tutorial : Installing Apache, PHP5, MySQL5, PhpMyAdmin 2.11 in Windows Vista/XP</a></p>
]]></content:encoded>
			<wfw:commentRss>http://visionmasterdesigns.com/tutorial-installing-ruby-on-rails-2-in-windows-vista-xp/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>
