2013-05-07 2 views
1

내 응용 프로그램의 경우 프로젝트 및 블로그 업데이트를 생성해야합니다. 각 프로젝트에 대해 Blogupdates를 만들 수 있습니다. 나는 richactor 레일즈를 서식있는 텍스트 편집기로 사용했다. 그것은 좋은 게시물.레일 - Sanitize Redactor 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 

답변

0

대답은 다음과 같이 아래의 항목을 수정하는 것입니다 :

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