我在smart_listing中创建新项目时遇到问题。我的路线
resources :cars do
resources :persons
end
我添加删除/编辑功能完美。但是当我需要创建新人时,我有这个错误:
undefined method `persisted?' for "/cars/1/persons/201":String
我的人员控制器
def create
@car = Car.find(params[:car_id])
@person = @car.persons.create(person_params)
end
我的create.js.erb
<%= smart_listing_item :persons, :create, car_person_path(@car, @person),
@person.valid? ? "person/person" : "person/form" %>
我的堆栈higlight第一行在create.js.erb中,错误如上。如何修复这个? :)
答案 0 :(得分:0)
看起来你正在使用错误的参数调用方法。根据gem的example,第三个参数应该是你模型的一个实例:
<%= smart_listing_item :users, :new, @new_user, "users/form" %>
在您的示例中,第三个参数是url
,而不是模型的实例。