Partial

From knowledgebase
Revision as of 09:52, 25 August 2020 by Dirkjan (talk | contribs) (Created page with "A partial is a snippet of HTML and Ruby code that can be reused in multiple locations: {{{ <h1>New post</h1> <%= render 'form' %> <%= link_to 'Back', posts_path %> }}} T...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A partial is a snippet of HTML and Ruby code that can be reused in multiple locations:

{{{

New post

<%= render 'form' %>

<%= link_to 'Back', posts_path %> }}}

The {{{<%= render 'form' %>}}} line is our first introduction to partials in Rails. A partial is a snippet of HTML and Ruby code that can be reused in multiple locations. In this case, the form used to make a new post is basically identical to the form used to edit a post, both having text fields for the name and title, a text area for the content, and a button to create the new post or to update the existing one.

Source: http://guides.rubyonrails.org/getting_started.html