I have a basic to do type app and I am trying to change the variable completed for an item to the current date/time when I click a checkbox. I found this post, which has led me to the following code structure:
My lists#show, on which items are created, checked off (updated), edited, and deleted:
<div class="container">
<div class="row" style="height: 70px"></div>
</div>
<div class="col-xs-10 col-xs-push-1 container">
<div class="md-well">
<h1 class="text-center"><%= @list.name %></h1>
<% if @items.count == 0 %>
<h4 class="text-center">You don't have any items on this list yet! Want to add some?<h4>
<% elsif @items.count == 1 %>
<h4 class="text-center">Only <%= @items.count %> Item To Go!</h4>
<% else %>
<h4 class="text-center">You Have <%= @items.count %> Items To Go!</h4>
<% end %>
<%= render 'items/form' %>
<% @items.each do |item|%>
<p>
<%= form_for [@list, item], class: "inline-block", id: 'item<%= item.id %>' do |f| %>
<%= f.check_box :completed, :onclick => "$this.parent.submit()" %>
<% end %>
<%= item.name %>
( <%= link_to "Delete", list_item_path(@list, item), method: :delete %> )
</p>
<% end %>
<div class="text-center">
<%= link_to "Back to My Lists", lists_path %>
</div> <!-- text-center -->
</div> <!-- well -->
</div> <!-- container -->
Here is my update method in my items_controller (which I believe has jurisdiction instead of the lists_controller even though it is the lists#show page because it is an item being updated:
def update
@list = List.friendly.find(params[:list_id])
@item = @list.items.find(params[:id])
@item.name = params[:item][:name]
@item.delegated_to = params[:item][:delegated_to]
@item.days_til_expire = params[:item][:days_til_expire]
@item.completed = params[:item][:completed]
@item.user = current_user
if @item.update_attributes(params[:item])
@item.completed = Time.now
end
if @item.save
flash[:notice] = "List was updated successfully."
redirect_to @list
else
flash.now[:alert] = "Error saving list. Please try again."
render :edit
end
end
Here is what is currently appearing:
And here are the two problems I'm having:
LESS IMPORTANT PROBLEM: The checkboxes should be displayed inline with the list items but aren't. My class
inline-blocksimply makes links to this in theapplication.scssfile:.inline-block { display: inline-block !important; }
MORE IMPORTANT PROBLEM: Even after the checkbox is clicked, the value for
completedremainsnilas per my console:[6] pry(main)> Item.where(name: "Feed Dexter") Item Load (0.1ms) SELECT "items".* FROM "items" WHERE "items"."name" = ? [["name", "Feed Dexter"]] => [#]
Any ideas how to make this functional?

update_attributesfollowed by asavein the same flow of action?update_attributesis a recent addition (while trying to implement the checkbox functionality) and thesavewas working prior to this change. The lack of functionality persists when both are combined under theupdate_attributes, removing thesave. Should they be combined anyway?id: "item"- if every form has the same id... html will be confused as to which form to submit when you do this:"$('#item').submit()"- it will pick the first one out of however many are on the page to submit. Make sure you give each form a unique id eg try:id: "item<%= item.id %>""$('#item<%= item.id %>').submit()"(note, not tested it will probably have bugs that you can fix with google). Though possibly you could do better with something like"$this.parent.submit()"or similarupdate_attributesdoes the same thing assave. Only in the first you pass an hash, and in the second you call the method from an object. So basically, it is the same thing. You can remove theupdate_attributescall and just usesave.