Ali Raza Khan
Ali Raza Khan

Reputation: 17

How to save HTML page in database?

How to save a HTML page in database using ruby?

I want to save several records in seed.rb `EmailEvent.create(email_event_id: 1, description:

"contact_agent_notification", html_page:"html page goes here"`

I am not sure whether this is the right approach for this or not. Any help will be appreciated.

Upvotes: 0

Views: 5672

Answers (1)

Devin Howard
Devin Howard

Reputation: 705

  1. You'll want the field in the database to be "text" instead of varchar, so it can hold all that html
  2. You'll need to make sure that you add .html_safe to the field your views when you output the html directly. (e.g. <%= email_event.html_page.html_safe %> )
  3. Security-wise, you definitely want to make sure that untrusted users aren't editing the HTML that's stored in the database. If not, you need to make sure you sanitize their input before you output it in a view.

As spickermann says, though, other than that things are pretty straightforward.

Upvotes: 4

Related Questions