Jquery Rails auto_html gem帮助-不另存为html
我正在尝试创建一个表单,在文本区域body\uhtml上使用auto\uhtml gem。我必须遵循这个指南 我有一个问题,没有浏览器刷新,预览不会被渲染,文本区域主体html不会像纯文本一样保存为html代码 我的模型:Jquery Rails auto_html gem帮助-不另存为html,jquery,ruby-on-rails,ruby,ruby-on-rails-3,gem,Jquery,Ruby On Rails,Ruby,Ruby On Rails 3,Gem,我正在尝试创建一个表单,在文本区域body\uhtml上使用auto\uhtml gem。我必须遵循这个指南 我有一个问题,没有浏览器刷新,预览不会被渲染,文本区域主体html不会像纯文本一样保存为html代码 我的模型: class Post < ActiveRecord::Base auto_html_for :body_html do html_escape image youtube(:width => 400, :height => 250
class Post < ActiveRecord::Base
auto_html_for :body_html do
html_escape
image
youtube(:width => 400, :height => 250)
link :target => "_blank", :rel => "nofollow"
simple_format
end
end
我的新表格:
<script type='text/javascript'>
function load(request) {
$('#code').text(request);
$('#preview').html(request);
}
function preview(value) {
$.getJSON("http://auto_html.rors.org/comments/preview?callback=?", value, function(data){
load(data);
});
}
function previewComment() {
preview({'t':$('#comment_body').val()});
}
$('#examples a').click(function() {
$('#comment_body').focus();
$('#comment_body').val( $(this).attr('href'));
previewComment();
});
$(function () {
$("#comment_body").focus();
previewComment();
});
$('#comment_form').delayedObserver(1, function(element, value) { previewComment() })
</script>
<h1>New post</h1>
<form id="comment_form" action="/posts" method="post">
<h3>Type or paste URLs</h3>
<%= simple_form_for @post do |f| %>
<%= f.input :titel, :label => 'Titel', :style => 'width:500;' %>
<%= f.text_area :body_html, :id => 'comment_body', :label => '125x125', :style => 'width:500;' %>
<%= f.button :submit, :value => 'Create post' %>
<% end %>
<h3>Code</h3>
<div id="code"></div>
<h3>Preview</h3>
<div id="preview"></div>
</form>
<%= link_to 'Back', posts_path %>
功能加载(请求){
$('代码')。文本(请求);
$('#preview').html(请求);
}
函数预览(值){
$.getJSON(“http://auto_html.rors.org/comments/preview?callback=?,值,函数(数据){
加载(数据);
});
}
函数previewComment(){
预览({'t':$('#comment_body').val()});
}
$('#示例a')。单击(函数(){
$(“#注释_body”).focus();
$('#comment_body').val($(this.attr('href'));
previewComment();
});
$(函数(){
$(“#注释_body”).focus();
previewComment();
});
$('#comment_form').delayedObserver(1,函数(元素,值){previewComment()})
新职位
键入或粘贴URL
'Titel',:style=>'宽度:500;'%>
'comment_body',:label=>'125x125',:style=>'width:500;'%
'创建帖子'%>
代码
预览
对于您的问题,将其保存为html。
您可以尝试以下方法:
def body_html
auto_html(self[:body_html]) { simple_format; link(:target => 'blank') }
end
或
您正在使用额外的sufix\u html
在输入端使用body(并在模型中声明auto_html_),在输出端使用*body_html*
您基本上需要更改为:
auto_html_for :body
形式如下:
...
<%= f.text_area :body, ...
。。。
auto_html_for :body
...
<%= f.text_area :body, ...