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 8992275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:54:57+00:00 2026-06-15T22:54:57+00:00

I have a project model and a categories model that has no relation. In

  • 0

I have a project model and a categories model that has no relation. In the form for the project model I would like to be able to select categories (check boxes) that the project belongs to (there can be many). Categories have one string heading and an array of categories that belongs to that heading.

I have this code without using simple_form it lists categories and check boxes, works like a charm. How would I do this using simple_form?

<% @categories.each do |category| %>
  <b><%= category.heading %></b><br />
  <% category.categories.each do |subcategory| %>
    <%= check_box_tag "project[categories][]", subcategory,@project.categories.include(subcategory) %><%=subcategory%><br />
  <% end %><br />
<% end %>

The model which form i try to update is as:

class Project
  include Mongoid::Document
  ...
  field :categories, type: Array
  ...
end

Categories are incidentally also stored in a Mongoid document but has no to projects relation.

class Category
  include Mongoid::Document
  field :heading, type: String
  field :categories, type: Array # should probably be called subcategories...
end
  • 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-06-15T22:54:59+00:00Added an answer on June 15, 2026 at 10:54 pm

    I’m unsure what you want exactly, but you can try something like this. If you can clarify what you’re asking, I’ll try to give a more detailed answer.

        <%= simple_form_for @document do |f| %>
            # other form inputs...
            <%= f.input :categories, collection: listOfCategoryNames, as: :check_boxes %>
            # other form inputs...
        <% end %>
    

    where listOfCategoryNames is an array of strings of all the category names.

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

Sidebar

Related Questions

I have an existing model for my project. I would like to switch to
I have project model that has many tasks. Both project and tasks can have
I have a project model that has a FK to a group model. Group
I have a Project model and it has some text attributes, one is summary.
I have a Java project that I'm trying to implement with a model-view-controller design.
I have a 'project' model. Each project has a 'gallery' and each gallery has
I have a MVC3 C# project that I have a model of FoodItem and
So I have a relationship of project to categories, such that a project can
I have a project model that has_many :tasks . I added a nested resource
I have a Project model that has_many :workers. In routes.rb, workers are a nested

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.