Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
tutorials:ruby_on_rails [2011/04/30 13:36] – created clemenstutorials:ruby_on_rails [2011/04/30 21:06] – [[[|Hello, world of Rails!]]] georg
Line 140: Line 140:
  
 <code> <code>
-  class SayController &lt; ApplicationController+  class SayController ApplicationController
   end   end
 </code> </code>
Line 149: Line 149:
  
 <code> <code>
-  class SayController &lt; ApplicationController+  class SayController ApplicationController
      def hello      def hello
      end      end
Line 159: Line 159:
 It might be annoying, but the error is perfectly reasonable (apart from the weird path). We created the controller class and the action method, but we haven't told Rails what to display. And that's where the views come in. Remember when we ran the script to create the new controller? The command added three files and a new directory to our application. That directory contains the template files for the controller's views. In our case, we created a controller named say, so the views will be in the directory app/views/say. To complete our Hello, World! application, let's create a template. By default, Rails looks for templates in a file with the same name as the action it's handling. In our case, that means we need to create a file called hello.rhtml in the directory app/views/say. (Why .rhtml? We'll explain in a minute.) For now, let's just put some basic HTML in there. It might be annoying, but the error is perfectly reasonable (apart from the weird path). We created the controller class and the action method, but we haven't told Rails what to display. And that's where the views come in. Remember when we ran the script to create the new controller? The command added three files and a new directory to our application. That directory contains the template files for the controller's views. In our case, we created a controller named say, so the views will be in the directory app/views/say. To complete our Hello, World! application, let's create a template. By default, Rails looks for templates in a file with the same name as the action it's handling. In our case, that means we need to create a file called hello.rhtml in the directory app/views/say. (Why .rhtml? We'll explain in a minute.) For now, let's just put some basic HTML in there.
  
-  &lt;html&gt;&lt;head&gt;&lt;title&gt;Hello, Rails!&lt;/title&gt;&lt;/head&gt; &lt;body&gt; +<code> 
-  &lt;h1&gt;Hello from Rails and SDF!&lt;/h1&gt; &lt;/body&gt; &lt;/html&gt;+<html><head><title>Hello, Rails!</title></head> <body 
 +<h1>Hello from Rails and SDF!</h1> </body> </html
 +</code>
  
 Save the file hello.rhtml, and refresh your browser window. You should see it display our friendly greeting. Notice that we didn't have to restart the application to see the update. During development, Rails automatically integrates changes into the running application as you save files. Save the file hello.rhtml, and refresh your browser window. You should see it display our friendly greeting. Notice that we didn't have to restart the application to see the update. During development, Rails automatically integrates changes into the running application as you save files.