Git Product home page Git Product logo

Comments (4)

spohlenz avatar spohlenz commented on May 18, 2024 7

Here is some sample code required to collection_select or collection_check_boxes work:

collection_select :author_ids, User.all, :id, :name, { label: "Author(s)" }, { multiple: true }

or

collection_check_boxes :author_ids, User.all, :id, :name, { label: "Author(s)" }

There might be a couple of things that are tripping you up: a) Make sure you use the _ids suffix on the field name, or b) For selects, { multiple: true } is a separate, second options hash (for HTML options). You can use an empty hash for the first options hash if you don't need to set a custom label.

from trestle.

spohlenz avatar spohlenz commented on May 18, 2024

Closing. Feel free to re-open if it hasn't solved your issue.

from trestle.

jtruzzi avatar jtruzzi commented on May 18, 2024

Hi sorry for the delay, i just tried it but i'm getting a "undefined method `services_ids' for #<Hotel" (that field is has_many relation to another model) . And when i remove the suffix, i get the multiple checkboxs showing correctly in the form, but when i post i get " #<ActiveRecord::AssociationTypeMismatch: Service(#70191805563060) expected, got String(#70191807635240)>".

Any idea what am i doing wrong?

from trestle.

spohlenz avatar spohlenz commented on May 18, 2024

Try with :service_ids (service is singular). This is a method defined by Rails when you declare a has_many association (http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many).

Without the _ids suffix, it is trying to assign the IDs (array of strings) to the association, when it is expecting an array of Service objects.

from trestle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.