-
-
Save softwhisper/2104580 to your computer and use it in GitHub Desktop.
Limpiar TextArea en Rails 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.expand_path(File.dirname(__FILE__) + "/../sanitize_tinymce_text") | |
include SanitizeTinymceText | |
namespace :html do | |
desc "Limpiar descripciones guarrillas con css inline y spans" | |
task :clean => :environment do | |
Publication.all.each do |pub| | |
pub.abstract = sanitize_text(pub.abstract) | |
pub.save | |
end | |
Project.all.each do |project| | |
project.description = sanitize_text(project.description) | |
project.save | |
end | |
Course.all.each do |course| | |
course.description = sanitize_text(course.description) | |
course.save | |
end | |
Profile.all.each do |profile| | |
profile.research_interest = sanitize_text(profile.research_interest) | |
profile.save | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= content_tag( | |
:p, | |
truncate( | |
strip_tags(@publication.abstract), | |
:length => 200, | |
:omission => " …").html_safe) unless publication.abstract.blank? | |
%> | |
<!-- | |
Asi corto las descripciones y les quito el HTML | |
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# En los modelos | |
class Publication < ActiveRecord::Base | |
include SanitizeTinymceText | |
before_save :clean_abstract | |
def clean_abstract | |
self.abstract = sanitize_text(self.abstract) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/sanitize_tinymce_text.rb | |
module SanitizeTinymceText | |
def sanitize_text(input_text) | |
unless input_text.blank? | |
begin | |
output_text = ActionController::Base.helpers.sanitize input_text, :tags => %w(b i em a br strong p), :attributes => %w(href) | |
rescue | |
output_text = input_text | |
end | |
else | |
output_text = input_text | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment