Search code examples
htmlruby-on-railsformsruby-on-rails-4simple-form

Using HTML in A Form


I am trying to create a form that accepts HTML. So that when I type <br> or use divs it understands and populated my content block accordingly. Can anyone point me in the right direction for this?

Here's the form I am using if that helps:

 <%= simple_form_for(@daily) do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <%= f.input :title %>
    <%= f.input :content %>
  </div>

  <div class="form-actions">
  <%= f.button :submit %>
  </div>
 <% end %>

Solution

  • Replace <%= f.input :content %> with <%= f.text_area :content %>. That doesn't do much but make a multi-line input area (looks better). However, when you display the data on your webpage (i.e. after you submit the form), you can put something like this:

    <p>@daily.content.html_safe</p>