0
votes

I have a threaded Post using Ancestry. When replying to a Post from another user I get :

on the line :

@post = current_user.posts.new(params[:post])

Started POST "/posts.js" for 127.0.0.1 at Tue Jun 07 13:50:19 +0300 2011
Processing by PostsController#create as JS Parameters: {"commit"=>"Post", "post"=>{"body"=>"

a

", "parent_id"=>"5", "discussion_id"=>"1"}, "authenticity_token"=>"RUra0Ndv67cgaGshBS5yCJMq5V6WG6OuZiqDbbWP5cc=", "utf8"=>"✓"} User Load (0.2ms) SELECT "users".* FROM "users" WHERE ("users"."id" = 33) LIMIT 1 Post Load (0.2ms) SELECT "posts".* FROM "posts" WHERE ("posts".user_id = 33) AND ("posts"."id" = 5) LIMIT 1 Completed in 238ms

ActiveRecord::RecordNotFound (Couldn't find Post with ID=5 [WHERE ("posts".user_id = 33)]):
app/controllers/posts_controller.rb:28:in `create'

How can I debug it ?

1

1 Answers

0
votes

My first pass would be to open rails console (at the prompt type 'rails console') and then try the following:

>> x = Post.find(5)

If you find it check the user_id on that record. Does it actually exist? If so, that's good to know.

Next I would take the SQL in your output above and run it manually in whatever db you use. If you're using SQLite3 you can do:

>> sqlite3 db/development.sqlite3

If it exists then it's a fair point to scratch your head. I suspect you will find that it's not there.

Is the link to reply to the post manually created in your view? Are you certain it's being built correctly--the two ids of interest are indeed what you intended them to be?

If it's correctly built then I would simply use the ruby debugger in your controller and begin stepping through code. If you're not familiar with the ruby debugger, you can get the gem as described in your Gemfile and then once it's in your gemset you can add this line of code where you want to breakpoint your code:

require 'ruby-debug'; debugger

Then you're free to explore as necessary.