Error- When assigning attributes, you must pass a hash as an argument

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Error- When assigning attributes, you must pass a hash as an argument



I have a funding table below is its admin funding show page. I want to add a feature so that the admin can add the cheque cut date directly from this page with a submit button at the end.


<%= form_tag add_cheque_date_path, :method => 'patch' do %>
<tbody>
<% @fundings.each do |funding| %>
<tr>
<td><%= funding.child.parent.parent_1_firstname %></td>
<td><%= funding.child.parent.email %></td>
<td><%= funding.activity_start_date %></td>
<td><%= funding.date_submitted %></td>
<td><%= funding.status %></td>
<td><%= date_field_tag "funding.cheque_cut_date", funding.cheque_cut_date %></td>
<td><%= link_to "View", parent_child_funding_path(funding.child.parent, funding.child, funding) %></td>
</tr>
<% end %>
</tbody>
</table>
<%= submit_tag "Submit" %>
<% end %>



parents_controller.rb


def add_cheque_date
@fundings= Funding.all
fundings = params[:fundings]
@fundings.each do |funding|
funding.update_attributes(:cheque_cut_date)
end
end

def funding_params
params.require(:funding).permit(:cheque_cut_date)
end



routes.rb


patch 'admin/application-status', to: 'parents#add_cheque_date', as: 'add_cheque_date'



When I click on submit below is the error i am getting. Kindly help me fix it.


When assigning attributes, you must pass a hash as an argument.




2 Answers
2



update_attributes updates all the attributes from the passed-in
Hash and saves the record. If the object is invalid, the saving will
fail and false will be returned.


update_attributes



But at funding.update_attributes(:cheque_cut_date) you put only key :cheque_cut_date without any value. Try next:


funding.update_attributes(:cheque_cut_date)


:cheque_cut_date


funding.update_attributes(funding_params)



Also, there is more than one problem. date_field_tag "funding.cheque_cut_date" create field with the name funding.cheque_cut_date, but params.require(:funding).permit(:cheque_cut_date) not permit key funding.cheque_cut_date. Change your fields name too:


date_field_tag "funding.cheque_cut_date"


funding.cheque_cut_date


params.require(:funding).permit(:cheque_cut_date)


funding.cheque_cut_date


<td><%= date_field_tag "funding[cheque_cut_date]", funding.cheque_cut_date %></td>

#or the same fields helpers type as other from this form
<td><%= f.date_field :cheque_cut_date %></td>



form.html.erb


<td><%= date_field_tag "cheque_cut_date[#{funding.id}]", funding.cheque_cut_date, min: Date.today %></td>



controller.rb


def add_cheque_date
fundings = params[:cheque_cut_date]
fundings.select do |k, v|
if v.present?
funding = Funding.find(k)
funding.update_attributes({cheque_cut_date: v})
end
end
end






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to scale/resize CVPixelBufferRef in objective C, iOS

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

SVG with two text elements. When one resizes due to textLength - how to resize the other one to the same character size