Skip to content

Instantly share code, notes, and snippets.

@pokk
Last active April 4, 2017 09:49
Show Gist options
  • Save pokk/57efcbc4bfe445503c4e4712492c4ea0 to your computer and use it in GitHub Desktop.
Save pokk/57efcbc4bfe445503c4e4712492c4ea0 to your computer and use it in GitHub Desktop.
Show raw html data into HTML

Introduction

Show raw HTML data and ruby variable.

Front xxx.html.erb

Concat

concat this key word is the same as echo in PHP.

Example

There is a array in the ruby controller that will be sent to a view.

@list = [2, 3, 5, 2, 3, 10, 6, 1]

There three ways to do it!

<div>
    <% @list.each { |n|
        concat raw "<p>"
        concat n
        concat raw "</p>"
    } %>
</div>
<div>
    <% @list.each do |n| %>
        <p><%= n %></p>
    <% end %>
</div>
<div>
    <% @list.each do |n| %>
        <-- This tag is provided by ruby's view helper.  -->
        <%= tag_p n %>
    <% end %>
</div>

Through this three we can make a good practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment