왜 이런 일이 발생하는지 이해할 수 없지만 friendly.id를 찾았음에도 기사의 ID가 쿼리되고있는 것 같습니다. 내가 발견 한 ID는 "0"입니다. 정확한 article_id (59)가 주석과 연관되어있는 경우에도 클릭 한 모든 기사에 대해 "0"입니다.Ruby on Rails 기사 show.html.erb에서 롤백로드
Processing by ArticlesController#show as HTML
Parameters: {"id"=>"javascript-8"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Article Load (0.7ms) SELECT "articles".* FROM "articles" WHERE "articles"."slug" = $1 LIMIT $2 [["slug", "javascript-8"], ["LIMIT", 1]]
(1.9ms) BEGIN
Article Load (0.3ms) SELECT "articles".* FROM "articles" WHERE "articles"."id" = $1 LIMIT $2 [["id", 0], ["LIMIT", 1]]
(1.1ms) ROLLBACK
Rendering articles/show.html.erb within layouts/application
Rendered comments/_comment_form.html.erb (19.3ms)
Comment Load (0.7ms) SELECT "comments".* FROM "comments" WHERE "comments"."article_id" = 59 ORDER BY created_at DESC
Rendered comments/_comment.html.erb (25.2ms)
편집 : 기사 컨트롤러
class ArticlesController < ApplicationController
before_action :authenticate_user!
before_action :set_article, only: [:show, :edit, :update, :destroy, :toggle_vote]
impressionist :actions=>[:show]
def show
@article_categories = @article.categories
@comments = Comment.where(article_id: @article).order("created_at DESC")
if @article.status == "draft" && @article.user != current_user
redirect_to root_path
end
end
private
def set_article
@article = Article.friendly.find(params[:id])
end
end
이전 필터 나 작업을 게시하십시오. '@ article' 자체가로드되고 있습니까? –
기사에 대한 링크를 렌더링하는 코드를 추가하십시오. 감사합니다 – Hirurg103
@CodyCaughlan before 필터로 편집 – doyz