Links ?

Part 3 / 3 : The Views

Keat
on Mon Sep 13 21:06:00 SGT 2004

For most part, Rails can already display whatever is required from the Controller. It has the default CRUD pages as neat templates (this site uses the default template stylesheet). However, other than per-object CRUD.. our forum application has a more special 'show' function that shows not only the Post object. Without much ado, the following is the crucial snippet of the show.rhtml :

<%= @post.send("subject") %>

<%= "" if @post.send("email") and @post.send("email") != "" %> <%= @post.send("author") %> <%= "| url" if @post.send("url") and @post.send("url") != "" %>
on <%= @post.send("created_at") %>

<%= @post.send("message") %>

<% if @comments.length > 0 %>

<% for entry in @comments %> <% end %>

Comments (<%=@comments.length%>)

<%= entry.send("message") %>
<%= "" if entry.send("email") and entry.send("email") != "" %> <%= entry.send("author") %> <%= "| url" if entry.send("url") and entry.send("url") != "" %>
on <%= entry.send("created_at") %> [<%= link_to "Delete", :action => "destroy_comment", :id => entry.id %>]

<% end %>

<< Back | Comment | Edit | Delete