Hi,
I have the following model that uses the plugin act_as_voteable:
class Video < ActiveRecord::Base
  belongs_to :user
  acts_as_voteable
  acts_as_commentable
  attr_accessible :url, :title, :description, :vote_count
  validates_presence_of :url, :title, :description
...
end
I also have an observer for Vote model, so each time a user cast a vote to a
video, or other content, I will update some info, including the vote_count
on video model or other content. The code that runs each time a vote is
created is:
def update_user_points_and_votes_count(vote, factor)
     content_clazz = Kernel.const_get(vote.voteable_type)
      content.vote_count +=1*factor
      content.save!
      ...
      ...
end
Basically, I will update vote_count when a vote is casted to a video, or
other kind of content that act_as_voteable.
The problem is that the instruction content.save! raises a validation
exception on :url (in the list of validates_presence_of). I think that it
will fail also on the other attributes in the list of validates_presence_of.
What I''m missing?
thank you,
Jp
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, I missed on line in the second block of code:
def update_user_points_and_votes_count(vote, factor)
     content_clazz = Kernel.const_get(vote.voteable_type)
     #missing
     content = content_clazz.fin(vode.voteable_id)
      content.vote_count +=1*factor
      content.save!
      ...
      ...
end
Thank you
On Fri, May 21, 2010 at 12:47 AM, Jonhy Pear
<jonhy.pear-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Hi,
>
> I have the following model that uses the plugin act_as_voteable:
>
> class Video < ActiveRecord::Base
>   belongs_to :user
>   acts_as_voteable
>   acts_as_commentable
>   attr_accessible :url, :title, :description, :vote_count
>   validates_presence_of :url, :title, :description
>
> ...
> end
>
>
> I also have an observer for Vote model, so each time a user cast a vote to
> a video, or other content, I will update some info, including the
vote_count
> on video model or other content. The code that runs each time a vote is
> created is:
>
> def update_user_points_and_votes_count(vote, factor)
>      content_clazz = Kernel.const_get(vote.voteable_type)
>
>       content.vote_count +=1*factor
>       content.save!
>       ...
>       ...
> end
>
> Basically, I will update vote_count when a vote is casted to a video, or
> other kind of content that act_as_voteable.
>
> The problem is that the instruction content.save! raises a validation
> exception on :url (in the list of validates_presence_of). I think that it
> will fail also on the other attributes in the list of
validates_presence_of.
>
> What I''m missing?
>
> thank you,
> Jp
>
>
-- 
João Miguel Pereira
http://jpereira.eu
LinkedIn: http://www.linkedin.com/in/joaomiguelpereira
joaomiguel.pereira-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
(351) 96 275 68 58
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, I missed on line in the second block of code:
def update_user_points_and_votes_count(vote, factor)
     content_clazz = Kernel.const_get(vote.voteable_type)
     #missing
     content = content_clazz.fin(vode.voteable_id)
      content.vote_count +=1*factor
      content.save!
      ...
      ...
end
Thank you
On Fri, May 21, 2010 at 12:47 AM, Jonhy Pear
<jonhy.pear-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Hi,
>
> I have the following model that uses the plugin act_as_voteable:
>
> class Video < ActiveRecord::Base
>   belongs_to :user
>   acts_as_voteable
>   acts_as_commentable
>   attr_accessible :url, :title, :description, :vote_count
>   validates_presence_of :url, :title, :description
>
> ...
> end
>
>
> I also have an observer for Vote model, so each time a user cast a vote to
> a video, or other content, I will update some info, including the
vote_count
> on video model or other content. The code that runs each time a vote is
> created is:
>
> def update_user_points_and_votes_count(vote, factor)
>      content_clazz = Kernel.const_get(vote.voteable_type)
>
>       content.vote_count +=1*factor
>       content.save!
>       ...
>       ...
> end
>
> Basically, I will update vote_count when a vote is casted to a video, or
> other kind of content that act_as_voteable.
>
> The problem is that the instruction content.save! raises a validation
> exception on :url (in the list of validates_presence_of). I think that it
> will fail also on the other attributes in the list of
validates_presence_of.
>
> What I''m missing?
>
> thank you,
> Jp
>
>
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.