On Nov 6, 2010, at 11:42 AM, Mark Lohstroh wrote:

> Hm, i totally forgot about the self. I'm still trying to learn ruby and
> everything. So the increaseVariable method looks like this. I just
> edited it so it could use self and so i could scale how much wanted to
> increase the variable.
> 
>  def increaseVariable(scale)
>   tempoints = 1 * scale
>    self.variable += tempoints
>    logger.debug "User variable is now #{user.variable}"
> end
> 
> so now this is what my controller looks like
> 
> def like
>    @post = Micropost.find(params[:id])
>    @user = @post.user_ids
>    respond_to do |format|
>      format.html
>    end
>    @user.increaseVariable(5)
>    @post.like_action
>    @user.save!
>    @post.save!
>  end
> 
> So when i run it, it says that there is an undefined method for
> "variable" but its up in the attr_accessible. What else could be wrong?

Does your users table have a 'variable' field?  Once it's in there you don't 
need to have attr_accessible at all.

Also, you're going to have a problem if variable is nil as "nil += 5" will 
throw an error.  So you need to either default it to zero in the database or 
look out for that in your model methods.

-philip

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to