undefined method `stringify_keys' for "progress":String
I get this error when put in the check_box_tag
status. How resolved?
<%= form_tag update_me_iteams_path, :method =>'put' do %>
<table>
<tr>
<th>Title</th>
<th>Text</th>
<th>Status</th>
<th></th>
</tr>
<% @iteams.each do |iteam| %>
<tr>
<td><%= iteam.id %></td>
<td><%= iteam.title %></td>
<td><%= iteam.text %></td>
<td><%= iteam.status %></td>
<td><%= link_to 'Show', iteam_path(iteam) %></td>
<td>
<%= check_box_tag "id[]", iteam.id, "status[]", iteam.status %>
</td>
</tr>
<% end %>
</table>
<%= submit_tag "Edit Checked" %>
<% end %>
My def
def update_me
@iteam = Iteam.find(params[:id])
if CHECK_STATUS_I_DONT_KNOWN == '0'
Iteam.where(params[:id]).update_attribute(status: 'DONE')
else
Iteam.where(params[:id]).update_attribute(status: 'progress')
end
end
CodePudding user response:
check_box_tag
signature is check_box_tag(name, value = "1", checked = false, options = {})
(https://apidock.com/rails/ActionView/Helpers/FormTagHelper/check_box_tag). You are passing item.status
as options which is causing the error.
Unfortunately it is not clear to me what checkbox you are trying to create here - why do you have "status[]"
there, is that for another checkbox? Or are you trying to pass two form params with a single checkbox - that's simply not gona work. I'd expect something more like:
check_box_tag "id[]", item.id
EDIT:
You do not need to send status
via the form, you already have it in your database. Update the form to have the above change and your action to:
def update_me
@iteams = Iteam.where(id: params[:id])
done_items = @iteams.where(status: 'DONE').pluck(:id)
progress_items = @iteams.where(status: 'progress).pluck(:id)
@iteams.where(id: done_items).update_all(status: 'progress')
@iteams.where(id: progress_items).update_all(status: 'DONE')
end