Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3406898
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:41:04+00:00 2026-05-18T05:41:04+00:00

When a user submits without any boxes checked. I need my ODM (Mongoid) to

  • 0

When a user submits without any boxes checked. I need my ODM (Mongoid) to update the record appropriately.

Having a bit of trouble with:

  <% Notification.all.each do |notification| %>
    <li>
      <%= check_box_tag 'user[notification_ids][]', notification.id, @user.notifications.include?(notification) %>
      <%= label_tag notification.description %>
    </li>
  <% end %>

The doc suggests that the check_box helper puts in a hidden input. The hidden field has the same name and its attributes mimic an unchecked check box. However, with the above code. I am going through a loop. Which is slightly different.

I tried:

<%= check_box('user_notification_ids_', '', options = {:index => notification.id, :checked => @user.notifications.include?(notification)}, checked_value = "1", unchecked_value = "0") %>

But whenever I submit, I get: illegal ObjectId format

Or should I create the hidden tag for notification_ids manually? Something like:

<%= hidden_field_tag 'user[notification_ids][]', '[]' %>

Looking to hear your feedback

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:41:05+00:00Added an answer on May 18, 2026 at 5:41 am

    Go with the first loop you included. It looks much simpler and looks like it does the same thing.

    If I understand your first sentence correctly, it sounds like you aren’t seeing the user’s notifications getting updated to none when they uncheck all the check boxes. When there are no check boxes checked, the browser won’t send that param back. It simply won’t be included in params so when you do something like:

    @user.update_attributes(params[:user])
    

    … notifications won’t get updated. In your controller, do this to ensure there is something set for params[:user][:notifications]:

    params[:user][:notifications] ||= []
    

    This is will set it to an empty array if there if it doesn’t exists and/or there’s no value there. This ensures that update_attributes will set it to none/empty.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So the chain of events is: The user submits a form. During the processing
I have a website with a contact form. User submits name, email and message
Details: Only disable after user clicks the submit button, but before the posting back
I've created a login submit form in HTML but for some reason user/password autocompletion
What is your best practical user-friendly user-interface design or principle? Please submit those practices
I have an ASP.NET MVC application, when a user clicks on the submit button
User equals untrustworthy. Never trust untrustworthy user's input. I get that. However, I am
User kokos answered the wonderful Hidden Features of C# question by mentioning the using
User-Defined Functions & Collating Sequences Full support for user-defined functions and collating sequences means
User A logs into a ticket management system to edit content on SomePage.aspx User

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.