我得到這個錯誤阿賈克斯錯誤on Rails的Ruby的無效arrguments
引發ArgumentError在列表#創建
'零' 不是加載ActiveModel兼容的對象。它必須實現 :to_partial_path。
這裏是我的index.html.erb文件
<div class="container">
<div class="row">
<div class="col-md-5"></div>
<div class="col-md-4">
<h4>Lists Homepage</h4>
</div>
</div>
<div class="row">
<div><%= link_to "New List", controller: "list", action: "new" , remote: true %> <%= image_tag("greenPlus.png", :alt => "add list", :height=>"15px", :width=>"15px") %></div>
</div>
<div class="row"> </div>
<div class="row">
<div class="col-md-4">
<div id="lists">
<% @lists.each do |piece_list| %>
<%= render :partial=>"list/piece_list", :object=>piece_list %>
<% end %>
</div>
<%= render "new" %>
</div>
</div>
</div>
這是create.js.erb
$("#new_list").before("<div id='flash-notice'><%= escape_javascript(flash[:notice]) %></div>");
$("<%= escape_javascript(render @piece_list) %>").appendTo("#lists");
$("#new_list")[0].reset();
這是piece_list.html.erb
<table class="table table-bordered">
<thead>
<tr>
<th><%= piece_list.name %></th>
<th><%= image_tag("redCross1.png", :alt => "delete list", :class => "deleteList", :height=>"15px", :width=>"15px") %></th>
</tr>
</thead>
<tbody class="list-index">
<% if piece_list.items.any? %>
<% piece_list.items.each do |item| %>
<%= render :partial=>"list/item", :object=>item %>
<% end %>
<% end %>
</tbody>
</table>
這
class ListController < ApplicationController
def index
@list = List.new
@lists = List.joins("LEFT JOIN `items` ON `items`.`list_id` = `lists`.`id`")
end
def create
@piece_list = List.create(list_params)
if @piece_list.save
flash[:notice] = "Thank you for submitting"
respond_to do |format|
format.html { redirect_to @lists }
format.js {}
end
else
format.html { render action: "new" }
format.js {}
end
end
private
def list_params
params.require(:list).permit(:name)
end
end
你能否提供一段代碼和更多的細節?它看起來像你試圖呈現一個集合,但出了問題,集合實際上沒有 – SpeedyWizard
控制器代碼呢?另外,它看起來像@ @ piece_list是零 - 你能確保它不是? – SpeedyWizard
我更新了上面的代碼。希望它有幫助 – anujeet