0
사용자가 주석을 남기면 새 주석과 항목이 만들어집니다. 나는 새 코멘트 양식을 통해 새 코멘트로 이전 항목을 연결하려고 시도하고 있지만 새로운 코멘트가 작성 될 때마다 새 코멘트 양식에 표시된 이전 항목이 아닌 item_id 항목을 주석 표의 새 항목 ID로 가져옵니다.하나의 작업으로 여러 모델 만들기
모델 :
class Item < ActiveRecord::Base
has_one :comment
class Comment < ActiveRecord::Base
belongs_to :Item
코멘트 컨트롤러 :
def create
@comment = Comment.new(comment_params)
@comment.create_item (line_id: @comment.line_id, view_dc_id: @comment.view_dc_id, irankdez_id: @comment.item.irankdez_id,
outputs_id: @comment.item.outputs_id, DataKeitimo: Time.current)
if @comment.save
redirect_to line_path(@comment.line_id, line_id: @comment.line_id, view_dc_id: @comment.view_dc_id, irankdez_id: @comment.item.irankdez_id, outputs_id: @comment.item.outputs_id), :flash => {:notice => "New Item is created!"}
else
...
end
end
코멘트 양식보기 :
<%= simple_form_for(@comment) do |f| %>
<%= f.hidden_field :item_id,
:value => params[:item_id] %> #passing old item_id over params
<%= f.hidden_field :line_id,
:value => params[:line_id] %>
<%= f.hidden_field :view_dc_id,
:value => params[:view_dc_id] %>
<
<%= f.hidden_field :outputs_id,
:value => params[:outputs_id] %>
<%= f.text_field :body, :required => true %>
<label for="textarea1">Komentaras</label>
<%= f.submit 'Submit', :class => 'btn' %>
<% end %>
이 저를 도와주세요.