Если вы используете jquery, вы можете использовать jjery ajax метод с dataType как JSON.
И вы также можете использовать тот же метод обновления restful, т.е. без создания какого-либо нового метода.
Просмотр -
<%= button_tag 'Activate', car_id: "22" , id: "activate_car" %>
Контроллер -
def update
@car = Car.find(params[:id])
respond_to do |format|
if @car.update(car_params)
format.html { redirect_to @car, notice: 'Car was successfully updated.' }
format.json { render :json: 'Successfully update' }
else
format.html { render :edit }
format.json { render json: @car.errors }
end
end
end
private
def car_params
params.require(:car).permit(:active)
end
JS -
$(document).on("click", '#activate_car', function () {
car_id = $(this).attr('car_id')
$.ajax({
url: "/cars/" + car_id,
type: "PUT",
data: {
active: true
},
dataType: "json",
success: function (response) {
alert(response)
}
});
});