2011-06-03 55 views
0

我有這樣的形式創建主題(又名標籤):HTML是不被過濾

<%= simple_form_for @video, :url => {:action => "topic_update"}, :html => {:id => "topic_form"}, :remote => true do |f| %> 
    <div class="topic_field_input"> 
     <%= f.input :topic_names, :class => "topic_field", :label => false, :placeholder => "Type a topic (enter to create new one)" %> 
    </div> 
<% end %> 

我創建它作爲一個虛擬屬性:

attr_accessor :topic_names 
after_save :assign_topics 

def assign_topics 
    self.topics << @topic_names.map do |name| 
     Topic.find_or_create_by_name(name.split(' ').map {|w| w.capitalize }.join(' ')) 
    end 
    end 
end 

我認爲它不」 t過濾html,因爲我要傳遞給find_or_create_by_name

如何修改代碼以過濾html?

+4

off topic,but'name.split('').map {| w | w.capitalize} .join('')'可以替換爲'name.titleize()' – 2011-06-03 21:27:54

回答

0

你可以強制逃避ERB::Util.h(@topic_names)在setter或getter中。