我试图提供一个表单来创建一条"消息"对于features_index页面上的每个功能。不幸的是,我收到错误"无法找到没有ID的功能。"
我是否正确地通过了当地人?参数似乎没有feature_id! (或许这是@的时间?
功能/索引视图:
- @features.each do |feature|
%tr
%td= feature.project_id
%td= feature.subject
%td= feature.details
%td= link_to 'Show', feature
%td= link_to 'Edit', edit_feature_path(feature)
%td= link_to 'Destroy', feature, :confirm => 'Are you sure?', :method => :delete
- if feature.messages.length > 0
- feature.messages.each do |message|
= render partial: "message_form", locals: {message: message}
- else
%td
= render partial: "message_form", locals: {message: Message.new(feature_id: feature)}
%br/
features / _message_form:
= simple_form_for(message) do |f|
= f.error_notification
.form-inputs
-# = f.input :feature_id
-# = f.input :sender
-# = f.input :receiver
= f.input :subject
= f.input :details
.form-actions
= f.button :submit
和消息控制器:
def create
@feature = Feature.find(params[:message][:feature_id])
@message = @feature.messages.build(params[:message])
respond_to do |format|
if @message.save
flash[:notice] = "Message sent!"
format.html { redirect_to @message, notice: 'Message was successfully created.' }
format.json { render json: @message, status: :created, location: @message }
else
flash[:notice] = "Message failed to send."
format.html { render action: "new" }
format.json { render json: @message.errors, status: :unprocessable_entity }
end
end
end
谢谢!
答案 0 :(得分:1)
我相信你需要一个hidden_field来将feature_id的参数传递给你的创建动作。
f.hidden_input :feature_id