1
我正在創建2個模塊,1)價目表,2)折扣清單。這兩個模塊在數據庫中共享一個名爲「relclili」的表格,它將存儲名爲「CustomerCustomer」的客戶ID,價目表「ListP」的ID和折扣列表「」的ID。當客戶被添加到折扣或價格列表中時,記錄會被創建爲relclili,但如果客戶被添加到價目表然後添加到折扣中,那麼不應該創建新記錄,而是修改記錄當客戶被添加到價目表更新控制器上的參數
我試圖使它工作創造,但它表明我的js文件 這是我得到的錯誤的錯誤:
ActionView::Template::Error (undefined method `CodCliente' for true:TrueClass):
1: $("#myclientadder_<%= @relclili.CodCliente %>").modal('hide');
2:
3: $("#container_relclilis").prepend('<%= j render @relclili %>'); //Prepend before append
4: $("#relclili_<%= @relclili.id %>").hide().fadeIn(1000);
app/views/relclilis/create.js.erb:1:in `_app_views_relclilis_create_js_erb___1051626349__1016832438'
這是我的創造動作:
def create
if Relclili.exists?(CodCliente: relclili_params[:CodCliente])
@relclili = (Relclili.find_by(CodCliente: relclili_params[:CodCliente]).first.update(ListaP: relclili_params[:ListaP]))
respond_to do |format|
format.html { redirect_to @relclili, notice: 'Relclili was successfully created.' }
format.json { render :show, status: :created, location: @relclili }
format.js {flash.now[:notice] = 'El cliente se ha agregado de forma exitosa.'} #ajax
end
else
@relclili = Relclili.new(relclili_params)
respond_to do |format|
if @relclili.save
format.html { redirect_to @relclili, notice: 'Relclili was successfully created.' }
format.json { render :show, status: :created, location: @relclili }
format.js {flash.now[:notice] = 'El cliente se ha agregado de forma exitosa.'} #ajax
else
format.html { render :new }
format.json { render json: @relclili.errors, status: :unprocessable_entity }
format.js {flash.now[:alert] = 'Error al agregar el cliente.'} #ajax
end
end
end
end
這是我create.js.erb
$("#myclientadder_<%= @relclili.CodCliente %>").modal('hide');
$("#container_relclilis").prepend('<%= j render @relclili %>'); //Prepend before append
$("#relclili_<%= @relclili.id %>").hide().fadeIn(1000);
$("#cliente_<%= @relclili.CodCliente %>").fadeOut(500, function(){
$(this).remove();
$(".child").remove();
});
$("#notice").html("<%= escape_javascript(render :partial => 'partials/flash' , :locals => { :flash => flash }).html_safe %>");
setTimeout(function(){
$('#notice').fadeIn("slow", function() {
$(this).create();
})
}, 1500);
謝謝我的朋友這解決了我的問題,非常感謝你的解釋 – luis31