[Rails] checkbox to update attribute
- by Jeff
[Updated a bit] I have a Task model that has a :completed boolean attribute. If I click on it I want it to execute the 'finish' method. The main problem is that I am displays a series of checkboxes in a list and subsequent checkboxes after the first one are ignored. The method is never called for the given task/checkbox combo.
I have this chunk of code in my view:
<% current_user.tasks.each do |t|%>
<% if t.completed == false %>
<%= check_box_tag :completed, true, checked = false %>
<%= observe_field :completed, :url => { :controller => 'tasks', :action => :finish , :id => t.id },
:frequency => 0.25,
:update => :completed,
:with => true
%>
and my finish method looks like this:
def finish
@task = Task.find(params[:id])
new = {:completed => true}
@task.update_attributes(new)
render :update do |page|
page.replace_html "taskListing", :partial => 'home/task_listing'
end