开发者

rails create error

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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜