Home arrow Ruby-on-Rails arrow Page 4 - Understanding Action Views in Ruby-on-Rails
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
TABLE OF CONTENTS:
  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
SEARCH DEVARTICLES

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
     def
hello
         
@time=Time.now
     end
end

and for the View:

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

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

class SayController < ApplicationController
  def
hello
    @time=Time.now
      @rule=”All sentence should have a starting, a
             mid section and an 
end except”
      @price=1000.123
  end
end

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

<html>
  <head>
    <title>Hello, Rails!</title>
  </head>
  <body>
    <br>The time now is
<%=@time%>
    <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) %>
  </body>
</html>

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 ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




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