I have the following gem (CKEditor)
for Rails. It's all working fine however the issue I have is that I'm trying to perform a word count with Rails and because CKeditor is saving a strange string this is not working.
Do you know if there is a way to use the raw command when a snippet is created so that the HTML isn't saved but the raw text is saved instead?
Let me know if you want me to paste any code but you can see what the content is being saved as below.
[6] pry(main)> s.content
=> "<p>YACHT!</p>\r\n"
[7] pry(main)>
or update my regex to not include the HTML.
Count shown below:
def size_limit
book_limit = self.book.size.to_i
word_count = self.content.scan(/\w+/).size.to_i
current_snippets_size = (self.book.get_word_count || 0) + word_count
errors.add(:base, "Content size is too big") unless word_count < BOOK_SIZE[book_limit]['per'] && current_snippets_size < BOOK_SIZE[book_limit]['total']
end
I tried using the sanitize gem but it didn't seem to work. I've also tried doing it like Nithin suggested below in the model.
word_count = self.content.gsub(/<.*?>/, "").scan(/\w+/).size.to_i
However that doesn't seem to work either. I'm a little lost here and have moved onto the other parts of the app until I can figure this out although this part is very crucial as it defines the total number of words per book or snippet.