首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails -净化Redactor

Rails -净化Redactor
EN

Stack Overflow用户
提问于 2013-05-07 00:12:55
回答 1查看 322关注 0票数 1

对于我的应用程序,我创建了项目和blogupdate。可以为每个项目创建Blogupdate。我使用了编者rails作为富文本编辑器。贴得很好。

但在回答我的问题HERE时,有人提到我应该对此进行消毒。因此,我遵循了建议,在遵循消毒过程之后,我得到了下面的错误。

问题:有人知道我需要做什么才能解决这个问题吗?

代码语言:javascript
复制
NameError in BlogupdatesController#create
undefined local variable or method `orig_text' for #<BlogupdatesController:0x007f9186570700>
app/controllers/blogupdates_controller.rb:68:in `sanitize_redactor'
app/controllers/blogupdates_controller.rb:14:in `create'

blogupdates_controller.rb

代码语言:javascript
复制
class BlogupdatesController < ApplicationController
  # used for sanitization user's input
  REDACTOR_TAGS = %w(code span div label a br p b i del strike u img video audio
              iframe object embed param blockquote mark cite small ul ol li
              hr dl dt dd sup sub big pre code figure figcaption strong em
              table tr td th tbody thead tfoot h1 h2 h3 h4 h5 h6)
  REDACTOR_ATTRIBUTES = %w(href)

  before_filter :authenticate_user! 

  def create
    @project = Project.find(params[:project_id])

    params[:blogupdate][:content] = sanitize_redactor(params[:blogupdate][:content])

    @blogupdate = @project.blogupdates.create!(params[:blogupdate])

    if @blogupdate.save
      redirect_to blogs_project_path(@project), notice: "Blog entry created."
    end   
  end

  private

  def sanitize_redactor(orig_input)
    stripped = view_context.strip_tags(orig_text)
    if stripped.present? # this prevents from creating empty comments
      view_context.sanitize(orig_text, tags: REDACTOR_TAGS, attributes: REDACTOR_ATTRIBUTES)
    else
      nil
    end
  end

end 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-27 07:22:02

答案是按以下方式修正以下项目:

代码语言:javascript
复制
def sanitize_redactor(orig_input)
  stripped = view_context.strip_tags(orig_input)
  if stripped.present? # this prevents from creating empty comments
    view_context.sanitize(orig_input, tags: REDACTOR_TAGS, attributes: REDACTOR_ATTRIBUTES)
  else
    nil
  end
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16409244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档