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.


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>


The if-blank attribute can be used to provide alternate content if this.blank?.

    <view if-blank="(None)"/>


The force attribute causes the permission check to be skipped.

    <view force/>

Additional Notes

  • The wrapper tag is <span> unless the field type is Text (different to String) where it is <div>. Use the inline or block attributes 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-wrapper attribute to remove the wrapper tag completely. e.g.

      <view:created_at no-wrapper/> -> June 09, 2008 15:36

Show Source

Related Tags

Edit this page