对于我的应用程序,我创建了项目和blogupdate。可以为每个项目创建Blogupdate。我使用了编者rails作为富文本编辑器。贴得很好。
但在回答我的问题HERE时,有人提到我应该对此进行消毒。因此,我遵循了建议,在遵循消毒过程之后,我得到了下面的错误。
问题:有人知道我需要做什么才能解决这个问题吗?
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
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 发布于 2013-05-27 07:22:02
答案是按以下方式修正以下项目:
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
endhttps://stackoverflow.com/questions/16409244
复制相似问题