Onay kutusu değiştiğinde ve teslim edildiğinde izlemek için Ruby on Rails 4 ile Ajax kullanmaya çalışıyorum ve onay kutusunu veritabanına kaydedin. Hata ayıklayıcıda bile hata görmüyorum. Düşüncesi olan var mı?Ruby on Rails alamıyorum 4 Checkbox -Update ile çalışmakta olan Ajax: ama onay kutusunu veya veritabanını değiştirmiyor
Kısa bir süre önce düzenleme yolunu değiştirdim çünkü 404 alıyordum. Bunu bir rotayla eşleştirdim.
Başarı işlevini ajax çağrısına ekledim ve tetikleniyor gibi görünüyor.
Bu
Şu anda ne olduğunu:$('#product_active').bind('change', function() {
console.log('changed');
var action = $(this).parents('form').attr('action')+"/edit";
var method = "GET";
var checked = $(this).attr('checked');
var data = $(this).attr('value');
data ^= 1;
$.ajax({
method: method,
url: action,
data: checked,
success: function() {
alert("AJAX Fired");
}
})
debugger;
});
budur:
def update
if @product.update(safe_params)
redirect_to [:edit, @product], flash: { notice: t('shoppe.products.update_notice') }
else
render action: 'edit'
end
end
product_controller Bu Haml içinde şeklidir
Bu
= form_for product, :remote => true do |f|
= f.check_box :active
= f.label :active, t('shoppe.products.active'), :remote => true
Bu js olduğunu tırmık rotalarından
products GET /products(.:format) shoppe/products#index
POST /products(.:format) shoppe/products#create
new_product GET /products/new(.:format) shoppe/products#new
edit_product GET /products/:id/edit(.:format) shoppe/products#edit
product GET /products/:id(.:format) shoppe/products#show
PATCH /products/:id(.:format) shoppe/products#update
PUT /products/:id(.:format) shoppe/products#update
DELETE /products/:id(.:format)
GÜNCELLEME:
$('.ajax').bind('change', function() {
$(this).parents('form').submit();
});
: Bana bir kod seti ile tüm ajax vurmak için izin formu ile bir gönderme gizli düğmeyi koyarak ve benim js değişen ve forma bir sınıfta ekleyerek sona erdi
Formu içeren gizli bir gönderme düğmesi belirledim ve j'lerimi bir forma ekleyerek bir ajax kodunu tek bir kodla vurmam için formda bir sınıf ekledim: –