> def like
>    @post = Micropost.find(params[:id])
>    @user = User.find(@post.user_id)
>    respond_to do |format|
>      format.html
>    end
>    @user.increaseVariable(@user)
>    @post.like_action(@post)
>    @user.save
>    @post.save
>  end
> 
> The routes file looks like this
> 
>  match "feed/:id/like" =>"feed#like"
>  match "feed/:id/dislike" =>"feed#dislike"
> 
> To me, this should all work correctly. And it did when I did the methods
> in the console, so i'm not worried about that. The problem is that the
> post will save, but the user will not. And i'm not sure why. Any
> thoughts?

We'd need to see the increaseVariable and like_action methods to know for sure. 
 Until then, change those save() calls to save!() calls and see what error gets 
thrown...  

Couple of other things you may want to consider...

@post = Micropost.find(params[:id])
@user = User.find(@post.user_id)

could be re-written as:

@post = Micropost.find(params[:id])
@user = @post.user

Also, the following two lines don't make much sense to me...

@user.increaseVariable(@user)
@post.like_action(@post)

Why would you call a method on an object and pass the object itself into the 
method?  You already have access to the object as 'self' within the method... 
???

And lastly, if you're updating an integer field in the Micropost table, don't 
set it and save it, but look at using increment_counter.  Do NOT use 
incremement (it sets and saves).  increment_counter will write an 'UPDATE ...' 
SQL clause that update the value in the database by one directly.

Good luck!

-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