[英]Save to Rails database html within elements
I am trying to save the HTML within an element when I load the view. 加载视图时,我试图将HTML保存在一个元素内。 I found this documentation but I am new to RoR and I get the following error:
我找到了此文档,但是我是RoR的新手,并且出现以下错误:
uninitialized constant HomeController::HTML
未初始化的常量HomeController :: HTML
Here is my html 这是我的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 控制器使用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? 也许我应该尝试使用javascript选择html并找到一种将其发送到数据库的方法? I don't want to refresh the page in order to save the html.
我不想刷新页面以保存html。
Thanks for your help. 谢谢你的帮助。
I'd put the html content in a partial then use ApplicationController.render or render_to_string 我将html内容放在一部分中,然后使用ApplicationController.render或render_to_string
ie Something like 即像
content = HomeController.render('path/to/partial')
or 要么
content = render_to_string(partial: 'path/to/partial')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.