隐蔽的“背部”通过 RedCloth 和 Acts-as-Textiled 编辑帖子时如何使用纺织品标记?
问题:如何在应用程序中将纺织品生成的 HTML“转换”回纺织品标记?
情况是这样的。通过在我的“帖子”模型中实现 RedCloth 和 actions-as-textiled,我成功地在我的 Rails 3 应用程序中拼凑出了一个穷人的博客编辑器。我使用“行为作为文本”来消除在“帖子”正文中编写内容的痛苦。
效果很好。但是,当我编辑帖子时,我在帖子正文中看到生成的 HTML。我想看到的是原始的纺织品标记。这可能吗?
预先感谢您的帮助!
这是我的帖子模型:
class Post < ActiveRecord::Base
has_many :tags
acts_as_taggable_on :tags
acts_as_textiled :title, :body
attr_accessible :tag_list, :tags, :title, :body, :post, :comments
validates :title, :presence => true
validates :body, :presence => true
default_scope :order => 'posts.created_at DESC'
这是我的“显示”方法的帖子视图:
<%= @post.title.html_safe %>
<%= @post.body.html_safe %>
Question: How can I "convert" my textile generated HTML back to textile markup in my app?
Here's the situtation. I managed to piece together a poor man's blog editor in my Rails 3 app by implementing RedCloth and acts-as-textiled in my "posts" model. I use acts-as-textiled to take the pain out of writing content in the body of my "posts".
It works great. However, when I edit the post I see the generated HTML in the post body. What I would like to see is the original textile markup. Is this possible?
Thanks in advance for your help!
Here is my post model:
class Post < ActiveRecord::Base
has_many :tags
acts_as_taggable_on :tags
acts_as_textiled :title, :body
attr_accessible :tag_list, :tags, :title, :body, :post, :comments
validates :title, :presence => true
validates :body, :presence => true
default_scope :order => 'posts.created_at DESC'
Here is my Posts view for the "Show" method:
<%= @post.title.html_safe %>
<%= @post.body.html_safe %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
输出:
就你的情况而言,我认为你应该这样做:
不过,我不知道这是否被认为是最佳实践。
文档:http://clothred.rubyforge.org/doc/html/index.html
Try this:
Output:
In your case, I think you should do:
I don't know if this is considered best practice, though.
Documentation: http://clothred.rubyforge.org/doc/html/index.html