DamnBigMan
(DamnBigMan@gmail.com)
January 30, 2008, 8:09pm
1
I have the following code (relevant section offset with dashes):
def create
@post = Post.new(params[:post])
@post.user_id = session[:user].id
@post.conversation_id = params[:conversation_id]
@conversation = Conversation.find(params[:conversation_id])
replies = @conversation.replies + 1
@posts = Post.find(:all, :conditions => ["conversation_id = ?",
params[:conversation_id]])
11175
(-- --)
January 30, 2008, 8:24pm
2
if @post.save
Conversation.update(params[:conversation_id], { :updated_at =>
Time.now, :replies => replies })
User.update(session[:user].id, { :num_posts =>
(session[:user].num_posts += 1) })
I assume the Conversation.update line is being called? i.e. that
@post.save is successful and it actually enters the if statement?
kopf1988
(kopf1988)
January 30, 2008, 8:27pm
3
Well, is there a reason for updating user twice? Aren't session[:user]
and @user supposed to represent the same object? If you're doing what
I think you are, shouldn't you set @user =
Users.find(session[:user].id), then operate only on @user - I wouldn't
store a user object in the session like that, and do work on it.
DamnBigMan
(DamnBigMan@gmail.com)
January 30, 2008, 8:28pm
4
Yeah sorry should have mentioned that. It is only being called once
too as the conversation count increments by one with each post.
DamnBigMan
(DamnBigMan@gmail.com)
January 30, 2008, 8:57pm
5
That did it. I didn't realize that when I put an object into the
session it gets looked up constantly.
Any idea why the User.update never runs?