开发者

checkbox to update attribute

开发者 https://www.devze.com 2022-12-23 00:30 出处:网络
[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

[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")%> 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号