Using Simple Form to update to-do list task on click

203 views Asked by At

I'm trying to use simple form to update a nested object on the click of a button. I'm making a to do list, with individual tasks/items nested within the overall list. The button click should update the task's completed attribute to true. The button click update worked fine before I tried recreating my table in Wice Grid. The same code no longer works in WiceGrid for some reason.

This update button worked when I was manually building out the table in HAML:

%td
  = simple_form_for [@checklist, item] do |f|
    = f.hidden_field :completed, :value => true
    %button.btn.btn-success.btn-sm Complete

Once I rebuilt the table using WiceGrid, I keep getting an error message. Below is the WiceGrid partial. What's the difference between the two?

:erb
  <%# show_filters: :when_filtered %>
  <%= grid(@tasks_grid) do |g|

    g.column  name:  'To Do', attribute: 'description' do |task|
      task.description
    end

    g.column  name:  'Status', attribute: 'completed' do |task|
      task.completed ? 'Completed' : ''
    end

    g.column name:  'Due Date', attribute: 'due_date' do |task|
      task.due_date.strftime("%B %d, %Y")
    end

    g.column do |task|
      "<button type='button' class='btn btn-primary btn-sm' data-toggle='modal' data-    target='#task_#{task.id}'>Edit</button>".html_safe
    end

    g.column do |task|
      link_to('Delete', wedding_checklist_checklist_item_path(@checklist, task), class: "btn btn    -warning btn-sm", :method => :delete, :data => { :confirm => 'Are you sure you want to     delete this task?' })
    end

    g.column do |task|
      simple_form_for [@checklist, task] do |f|
        f.hidden_field :completed, :value => true
        f.submit "Complete", class: "btn btn-success btn-sm"
      end
    end

  end -%>

Here's the checklist_items_controller.rb file:

private

def checklist_item_params
  params.require(:checklist_item).permit(:event_checklist_id, :description, :due_date,   :completed, :user_id)
end

The error I keep getting is: param is missing or the value is empty: checklist_item

I thought checklist_item had been passed through by the "task"?

1

There are 1 answers

0
AudioBubble On BEST ANSWER

I used a partial and somehow the Complete function works now:

g.column do |task|
  render partial: 'complete_task', locals: {item: task}
end