<view>
Provides a read-only view tailored to the type of the object being viewed. <view> is a polymorphic tag which means that there are a variety of definitions, each one written for a particular type. For example there are views for Date, Time, Numeric, String and Boolean. The type specific view is enclosed in a wrapper tag (typically a <span> or <div>) with some useful classes automatically added.
Usage
Assuming the context is a blog post…
-
Viewing a DateTime field:
<view:created_at/> -> <span class="view blog-post-created-at">June 09, 2008 15:36</span> -
Viewing a String field:
<view:title/> -> <span class="view blog-post-title">My First Blog Post</span> -
Viewing an Integer field:
<view:comment_count/> -> <span class="view blog-post-comment-count">4</span> -
Viewing the blog post itself results in a link to the blog post (using Rapid’s <a> tag):
<view/> -> <span class="view model:blog-post-1"><a href="/blog_posts/1">My First Blog Post</a></span>
if-blank
The if-blank attribute can be used to provide alternate content if this.blank?.
<view if-blank="(None)"/>
force
The force attribute causes the permission check to be skipped.
<view force/>
Additional Notes
-
The wrapper tag is
<span>unless the field type isText(different toString) where it is<div>. Use theinlineorblockattributes to force a<span>or a<div>, e.g.<view:body/> -> <div class="view blog-post-body">This is my blog post body</div> <view:body inline/> -> <span class="view blog-post-body">This is my blog post body</span> <view:created_at block/> -> <div class="view blog-post-created-at">June 09, 2008 15:36</div> -
Use the
no-wrapperattribute to remove the wrapper tag completely. e.g.<view:created_at no-wrapper/> -> June 09, 2008 15:36
Related Tags
Edit this page