Reputation: 290
I am trying to save the HTML within an element when I load the view. I found this documentation but I am new to RoR and I get the following error:
uninitialized constant HomeController::HTML
Here is my html
<div class="container_content">
<h2>The element I want to save in my db</h2>
<p>And this one too!</p>
</div>
The controller rendering the view with the html
class HomeController < ApplicationController
def index
end
def show
selector = HTML::Selector.new "div.container_content"
Content.create html: selector, team_id: 1, last_update: Time.now
end
end
Maybe I should try to select the html with javascript and find a way to send it to the database? I don't want to refresh the page in order to save the html.
Thanks for your help.
Upvotes: 0
Views: 211
Reputation: 10406
I'd put the html content in a partial then use ApplicationController.render or render_to_string
i.e. Something like
content = HomeController.render('path/to/partial')
or
content = render_to_string(partial: 'path/to/partial')
Upvotes: 1