通过Zurb Reveal - Rails编辑评论,嵌套表格

时间:2016-10-31 14:01:52

标签: ruby-on-rails ruby zurb-foundation-6 zurb-reveal

首先,这是错误

First argument in form cannot contain nil or be empty

我所拥有的是Thread模型和控制器以及Answer模型和Controller。 而我想要做的是通过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">&times;</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

有什么建议吗?错误可能在哪里?

0 个答案:

没有答案