Home arrow Ruby-on-Rails arrow Page 4 - Understanding Action Views in Ruby-on-Rails

Understanding Action Views in Ruby-on-Rails

Continuing our discussion of Ruby-on-Rails, this article covers the basic services provided by the ActionView. The ActionView helps you present data to your users. Keep reading to learn some terminology and study an example application.

Author Info:
By: A.P.Rajshekhar
Rating: 5 stars5 stars5 stars5 stars5 stars / 12
August 15, 2006
  1. · Understanding Action Views in Ruby-on-Rails
  2. · ActionView: Templates and Formatting Helpers
  3. · ActionView: Pagination and Layouts
  4. · Rails in the Real World

print this article

Understanding Action Views in Ruby-on-Rails - Rails in the Real World
(Page 4 of 4 )

Let's take the simple application that was created in the last part a little further. To jog your memory here is the code for the Controller:

class SayController < ApplicationController

and for the View:

    <title>Hello, Rails!</title>
    <h1>Hello from Rails! The time now is<%=@time%></h1>

Now let's add a string and float variable to the controller.

class SayController < ApplicationController
      @rule=”All sentence should have a starting, a
             mid section and an 
end except”

In the View let's use the formatting helpers (the view is already a template):

    <title>Hello, Rails!</title>
    <br>The time now is
    <br>The time now in words
<%= distance_of_time_in_words(@time, Time.local(2005, 12, 25)) %>
    <br>The highlight works like this
<%= highlight(@rule, "sentence") %>
    <br>The price 1000.123 in Canadian dollar is
<%= number_to_currency(@price, :unit => "CAN$", :precision => 2) %>

That’s all for this part. In the next part the last piece of the puzzle, i.e. the Model component, will be discussed. Once that is completed, I will start to discuss all the components in relation to each other using a project. Till then…

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials