Closed localguiding closed 12 years ago
Hi Alvaro!
You probably want the Rakismet stuff on the Message class, since it seems like that's the individual object you want to test for spam. You could do it like this:
class Conversation < ActiveRecord::Base
has_many :messages
accepts_nested_attributes_for :messages
end
class Message < ActiveRecord::Base
belongs_to :conversation
include Rakismet::Model
rakismet_attrs :content => :body
end
Then you could ask a conversation object if any of its messages are spam:
@conversation.messages.any? &:spam?
You could put that into a validation hook and do something (throw an error, mark it for review, etc.) if any messages are marked as spam.
Let me know if you have more questions!
Thanks for you reply.
And yes, I have some other questions :) As you suggested I have included it in the model Message:
rakismet_attrs :author => proc { conversation.contact_name },
:author_email => proc { conversation.contact_email },
:content => :body,
:comment_type => "ct"
As you can see, beside :content => :body, I have also matched rakismet attributes with the parent model (conversation) attributes. Is it ok to mix associated attributes and direct associations (i.e. :content => :body) as I did ?
Alvaro.
Yup, that's totally ok!
Thanks you !
Hi, first of all cool gem ! I have some doubts about how or where define akismet attributes when dealing with these 2 models:
My idea is to call spam? before calling Conversation.save in my ConversationsController. The problem is that I don't know how match asktmet "content" attribute with Message.body
Should I do something like:
Thanks in advance.