Hi

I am trying to implement Ajax commenting to 'stories' and am having troubles. I have a Story, Comment, and User model. At the moment, i can add comments using Ajax, but when i refresh the page, the comments dissappear. When i look in my database, i can see that the story_id field of the comments table is always NULL. So this is not being saved. Below is my code, how do i get the story_id field to be saved on creation of a new comment? I have tried changing the code, particularly in the create action of the comments controller. But whenever i do, i get errors and cannot even add any comments at all....

comments_controller.rb:
class CommentsController < ApplicationController

def new
@comment = Comment.new
end

def create

@comment = Comment.new(params[:comment])
@comment.user = User.find(current_user)
@comment.story = Story.find_by_id
if @comment.save
respond_to do |format|
format.html # all html requests
format.js #{ render :action => "create.rjs" }# all ajax requests
format.xml # all XML requests
end
end
end

end

stories_controller.rb:
class StoriesController < ApplicationController

def show
@story = Story.find(params[:id])
@comments = @story.comments.find(:all)
respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @story.to_xml }
end
end

end

story/show.rhtml:
<h3>Comments:</h3>

<div id="comments">
<%= render :partial => 'comments/comment', :collection => @story.comments %>
</div>

<div id="new_comments">
<% remote_form_for(:comment, :url => comments_path) do |f| %>
<%= f.text_area :body, :rows => '7', :cols => '61' %> <br />
<%= submit_tag "Add a Comment!" %>
<% end %>
</div>

comment/_comment.rhtml:
<div id="comment_<%= comment.id %>" class="comment">
<p><%= comment.body %><br />
Commented on <%= comment.created_at.to_s(:long) %> by <%= comment.user.login %></p>
</div>

In the create action;
Doing this gave me errors: if @story.comments << @comments
So did putting: @story = Story.find(params[:id])

How can i alter the code to fix this? What am i doing wrong?

Many thanks,

PJ.