First of all this is the error
First argument in form cannot contain nil or be empty
What I have is a Thread model and controller and a Answer model and Controller. And what I am trying to do is edit the answer on the show page of the thread via a zurb Reveal Modal.
and this what my code looks like
Thread Modal
class Thread < ApplicationRecord
belongs_to :user
has_many :answers
extend FriendlyId
friendly_id :subject, use: :slugged
end
Answer Model
class Answer < ApplicationRecord
belongs_to :user
belongs_to :thread
end
Answer Controller
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
Show Thread
<%= render @thread.answers %>
Answer Partial
<% 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>
Answer Edit Form Partial
<h1>Edit Answer</h1>
<%= form_for([@thread, @answer]) do |f| %>
<%= f.text_area :content, :rows => "10" %>
<%= f.submit "Update", :class => "button add-thread" %>
<% end %>
I get the error when I try to open a thread#show
its says the error is here
ArgumentError in Threads#show
<%= form_for([@thread, @answer]) do |f| %>
Trace of template inclusion: app/views/answers/_answer.html.erb, app/views/threads/show.html.erb
Any suggestions ? where may the error be ?