Answer the question
In order to leave comments, you need to log in
How to set check_box_tag in Rails using JavaScript?
I have a task, I need to put a check_box_tag, by clicking on which the status of the task should change from false to true and vice versa.
Here is what I tried and it didn't work
<%= check_box_tag 'status', 'complete', task.status, data: { action: 'task_status', remote: true, task_id: task.id } %>
def task_status
@task = Task.find(params[:task_id])
if @task.status == COMPLETE_STATUS
@task.status = nil
else
@task.status = COMPLETE_STATUS
end
@task.save
end
<%= check_box_tag :status, 'complete', task.status %>
<script>
$('#status').change(function() {
$.get('todo/task_status?task_id='+$(task.id).val(), function(data, status) {
if(status == 'success'){
alert(data)
}
})
});
</script>
def task_status
@task = Task.find(params[:task_id])
if @task.status == COMPLETE_STATUS
@task.status = nil
else
@task.status = COMPLETE_STATUS
end
render text: 'success'
<%= check_box_tag :status, 'complete', task.status, task_id: task.id %>
<script>
$('#status').change(function() {
$.get('todo/task_status?task_status='+$(this).val(), function(data, status) {
if(status == 'success'){
alert(data)
}
})
});
</script>
def task_status
@task = Task.find(params[:task_id])
@task.status = params[:task_status]
render text: 'success'
end
Answer the question
In order to leave comments, you need to log in
stackoverflow.com/questions/14780929/rails-checkbo...
Same problem solved
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question