[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
Nevermind I figured it out:
Here it is:
<% current_user.tasks.each do |t|%>
<% if t.completed == false %>
<%= check_box_tag t.id, true, checked = false %>
<%= observe_field t.id, :url => { :controller => 'tasks', :action => :finish , :id => t.id },
:frequency => 0.25,
:update => :completed,
:with => true
%>
<%= link_to t.title , t %> - <%= t.due_date.strftime("%B %d, %Y %X %p")%>
精彩评论