チェックボックスがチェックされている場合、データベースの「必要な」値を更新したいだけです。そして、スクリプトは以下のリストです
$('td div').find('input[type=checkbox]').click(function(){
$.ajax({
type: "PUT",
dataType: "script",
url: '/ecs/2',
contentType: 'application/json',
data: JSON.stringify({ ecs:{needed:'N'}, _method:'put' })
}).done(function( msg )
{
alert( "Data Saved: " + msg );
});
});
}); コントローラーのコードは標準です。
# PATCH/PUT /ecs/1
# PATCH/PUT /ecs/1.json
def update
respond_to do |format|
if @ec.update(ec_params)
format.html { redirect_to @ec, notice: 'Ec was successfully updated.' }
format.json { head :no_content }
format.js
else
format.html { render action: 'edit' }
format.json { render json: @ec.errors, status: :unprocessable_entity }
format.js
end
end
end
EC はモジュールの名前で、必要なのは列の名前です。必要な ec の新しい値を id=2 で更新したいだけです。しかし今、私は常に BAD REQUEST に遭遇しました。どこに問題があるのか わかりません。