0

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 %>
2
  • Is not clear. Where do you want to write divs and brs? Commented Jul 18, 2015 at 19:18
  • Sorry about that. This is the form I fill out for a blog post on a webpage. Instead of typing text into the content input - I'd like to paste some HTML. So that way when I press submit, the page where I view the blog post is formatted accordingly. However now it just shows the html as text. It isn't processing it Commented Jul 18, 2015 at 19:26

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

Perfect. Thanks Ryan!
No problem. Now, make sure that this form isn't public facing. Because people could input some <script> tags and (IIRC) that JavaScript would run and can be dangerous.
Why you don't have a textarea also using simple form (input instead of textarea)? Is your field a text (not a string) in the database?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.