레일 4.0.8을 사용하고 있습니다. 'Things'라는 모델에 댓글 섹션을 추가했지만 댓글 제출 버튼을 누르면 'param is missing'또는 'value is empty : thing'과 같은 오류가 계속 발생합니다. 이것은 오류가 Things # 컨트롤러에 있다고 말합니다. 내가 도대체 뭘 잘못하고있는 겁니까?오류 : param이 없거나 값이 비어 있습니다. 건
업데이트 : 양식에서 URL 경로를 제거했지만 "오류 ID없이 찾을 수 없습니다"라는 새로운 오류가 반환됩니다. 오류는 Comments # Controller에 있습니다. THING/SHOW
<div id= "thing">
<h1>
<%= @thing.name %>
</h1>
<br>
<div id= "commentsection">
Comments
<div id= "comments">
<br>
<% @thing.comments.each do |c| %>
<%= c.username %>
<br>
<%= c.text %>
<% end %>
<%= form_for @comment, :url => thing_path do |f| %>
<%= f.label :username %>
<%= f.text_field :username %>
<%= f.label :comment %>
<%= f.text_field :text %>
<%= f.submit "Enter", class: "btn btn-small btn-primary" %>
<% end %>
</div>
</div>
</div>
사항 컨트롤러
VIEW
class ThingsController < ApplicationController
def show
@thing = Thing.find(params[:id])
@thing.comments.build
@comment = Comment.new
end
def index
end
def new
@thing = Thing.new
@things = Thing.all
end
def create
@thing = Thing.new(thing_params)
if @thing.save
redirect_to @thing
else
render 'new'
end
end
private
def thing_params
params.require(:thing).permit(:name, :avatar)
end
end
코멘트 컨트롤러 (오류가 어디 선 주위에 별표를 넣어)
class CommentsController < ApplicationController
def show
@comment = Comment.find(params[:id])
end
def new
@comment = Comment.new
@comments = Comment.all
end
def create
****@thing = Thing.find(params[:thing_id])****
@comment = @thing.comments.create(comment_params)
redirect_to thing_path(@thing)
end
end
private
def comment_params
params.require(:comment).permit(:user, :text, :upvotes, :downvotes, :thing_id)
end
end
의 노선
Website::Application.routes.draw do
get "comments/new"
get "comments/show"
get "things/new"
root 'home_page#home'
get "all/things/new" => 'things#new'
get "all/allthings"
resources :things
resources :good_comments
get "things/show"
get "things/results"
end
감사처럼 보일 것입니다! 나는 무의미한 URL 경로를 제거했지만 Comments # Controller에서 "ID 없이는 찾을 수 없습니다"라는 새로운 오류가 있습니다. 왜 그럴지 모른다고 생각 해요? 내 모델이 올바르게 설정되었고 각 댓글에 thing_id가 있습니다. –
@ user3739453 양식은'<% = form_for @thing, @comment do %> '이어야합니다''주석 컨트롤러'에서 당신은''params [: thing_id]'를 요구하고 있습니다. 그러나 검사하면 폼이 현재 생성하고있는 url 그것은'/ comments'입니다. ''/ thing/: thing_id/comments ''일 필요가 있습니다.''resources : things do : comments end' – kittyminky
좋아요, 이제 나에게 "알 수없는 속성을 쓸 수 없습니다. 'html' "을 표시하고 줄을 강조 표시합니다. <% = form_for @thing, @comment do | f | %>'. –