首先这是错误
First argument in form cannot contain nil or be empty
我拥有的是一个 Thread 模型和控制器以及一个 Answer 模型和控制器。我想要做的是通过 zurb Reveal Modal 在线程的显示页面上编辑答案。
这就是我的代码的样子
线程模态
class Thread < ApplicationRecord
belongs_to :user
has_many :answers
extend FriendlyId
friendly_id :subject, use: :slugged
end
答案模型
class Answer < ApplicationRecord
belongs_to :user
belongs_to :thread
end
应答控制器
def edit
@thread = Thread.friendly.find(params[:thread_id])
@answer = @thread.answers.find(params[:id])
render :layout => false
end
def update
@thread = Thread.friendly.find(params[:thread_id])
@answer = @thread.answers.find(params[:id])
respond_to do |format|
if @answer.update(params[:answer].permit(:content))
format.html { redirect_to thread_path(@thread) }
format.json { render :show, status: :ok, location: @answer }
else
format.html { redirect_to @thread, alert: "Unable to save your post" }
format.json { render json: @answer.errors, status: :unprocessable_entity }
end
end
end
显示线程
<%= render @thread.answers %>
回答部分
<% if current_user.present? && current_user.id == answer.user_id %>
<ul class="edit-links pull-right">
<li>
<%= link_to 'Edit', edit_thread_answer_path(answer.thread, answer), :remote => true, class: "edit", "data-open" => "editModal", "data-open-ajax" => edit_thread_answer_path(answer.thread, answer) %>
</li>
<li>
<%= link_to 'Destroy', [answer.thread, answer], method: :delete, data: { confirm: 'Are you sure?' }, class: "destroy" %>
</li>
</ul>
<% end %>
<p>
<%= simple_format answer.content %>
</p>
<div id="editModal" class="reveal" data-reveal>
<%= render :partial => 'answers/edit_form' %>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>
回答编辑表格部分
<h1>Edit Answer</h1>
<%= form_for([@thread, @answer]) do |f| %>
<%= f.text_area :content, :rows => "10" %>
<%= f.submit "Update", :class => "button add-thread" %>
<% end %>
当我尝试打开线程时出现错误#show
它说错误在这里
ArgumentError in Threads#show
<%= form_for([@thread, @answer]) do |f| %>
模板包含的痕迹:app/views/answers/_answer.html.erb、app/views/threads/show.html.erb
有什么建议么 ?错误可能在哪里?