ruby on rails - Saving check box values to the database -


I allow users to group groups together using checkboxes in new and edit forms:

  & lt;% current_user.contacts.all.each do | Contact | & Gt%; & Lt;% check = group @contacts.include? (Contact)% & gt; & lt;% = check_box_tag "Contact []", contact.id,% checked & gt; & Lt;% = f.label contact.name% & gt; & Lt;% end% & gt;   

So far, I was able to use the following code to create a group:

  def creategroup = current_user.groups.new (group_prem) @ Contact = contact.fund (param [: contact]) @ group.contacts & lt; & Lt; @ Contact if @ group.Save ...... end   

To ensure that the checked values ​​are not added to a group during the update action I have a hidden tag form.

  & lt;% = hidden_field_tag ​​"contact []", "%" & Lt;% current_user.contacts.all.each do | Contact | & Gt%; & Lt;% check = group @contacts.include? (Contact)% & gt; & Lt;% = check_box_tag "Contact []", contact.id, Checked% & gt; & Lt;% = f.label contact.name% & gt; & Lt;% end% & gt;   

Now, I am unable to create or update a group because the Hidden_field value has also been passed. No active record found: All contacts with 'id' could not be found: (, 3, 4) (2 results were found, but 3 was in search of) Error How can I solve this?

I think you want to view the hidden area tag as zero instead of the empty space

  & lt;% = hidden_field_tag ​​"contact []", zero%>   

But as you are using the railroad 4 then there may be collection_check_boxes

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -