只需在我的rails应用程序中添加了新的评论功能,就偶然发现了此问题。我在Pics#show中收到了NoMethodError,该错误来自我的_comment.html.haml部分。
我可以在显示页面上看到评论主题,但是发布评论后我得到了。可以返回未注释的照片,但不能转到我已评论的照片。
我已经盯着代码看了一段时间了,我需要一双新鲜的眼睛。
Started GET "/pics/14" for 127.0.0.1 at 2018-12-19 23:44:51 +0000
(0.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
↳ /Users/alexfurtuna/.rvm/gems/ruby-2.4.0/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
Processing by PicsController#show as HTML
Parameters: {"id"=>"14"}
Pic Load (0.4ms) SELECT "pics".* FROM "pics" WHERE "pics"."id" = $1 LIMIT $2 [["id", 14], ["LIMIT", 1]]
↳ app/controllers/pics_controller.rb:53
CACHE Pic Load (0.0ms) SELECT "pics".* FROM "pics" WHERE "pics"."id" = $1 LIMIT $2 [["id", 14], ["LIMIT", 1]]
↳ app/controllers/pics_controller.rb:9
Rendering pics/show.html.haml within layouts/application
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/views/pics/show.html.haml:14
(0.7ms) SELECT COUNT(*) FROM "votes" WHERE "votes"."votable_id" = $1 AND "votes"."votable_type" = $2 AND "votes"."vote_flag" = $3 [["votable_id", 14], ["votable_type", "Pic"], ["vote_flag", true]]
↳ app/views/pics/show.html.haml:20
Comment Load (0.5ms) SELECT "comments".* FROM "comments" WHERE "comments"."commentable_id" = $1 AND "comments"."commentable_type" = $2 [["commentable_id", 14], ["commentable_type", "Pic"]]
↳ app/views/pics/show.html.haml:28
Rendered collection of comments/_comment.html.haml [1 times] (153.0ms)
Rendered pics/show.html.haml within layouts/application (220.1ms)
Completed 500 Internal Server Error in 267ms (ActiveRecord: 13.0ms)
ActionView::Template::Error (undefined method `comment_comments_path' for #<#. <Class:0x007fa535ee08b8>:0x007fa535ee9d50>
Did you mean? pic_comment_comments_path):
2: = comment.body
3: %small
4: Submitted #{time_ago_in_words(comment.created_at)} ago
5: = form_for [comment, Comment.new] do |f|
6: = f.text_area :body, placeholder: "Add a Reply"
7: %br/
8: = f.submit "Reply"
app/views/comments/_comment.html.haml:5:in `_app_views_comments__comment_html_haml___2866288612795974586_70173756400620'
app/views/pics/show.html.haml:28:in `_app_views_pics_show_html_haml___2738689311384334047_70173775563600'
这是我的_comment部分。
%li
= comment.body
%small
Submitted #{time_ago_in_words(comment.created_at)} ago
= form_for [comment, Comment.new] do |f|
= f.text_area :body, placeholder: "Add a Reply"
%br/
= f.submit "Reply"
%ul
= render partial: 'comments/comment', collection: comment.comments
答案 0 :(得分:0)
一切都已修复,并且可以正常工作。必须传递@pic变量。谢谢