Comments (4)
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.
Closing. Feel free to re-open if it hasn't solved your issue.
from trestle.
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.
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)
- adding maps HOT 3
- Saving seems to not provide a notice of saving but saves anyways HOT 1
- select empty if no relation? HOT 2
- How to add icons in sidebar buttons? HOT 4
- How to fix "to_param called on non-resourceful admin. You may need to explicitly specify the admin." HOT 1
- Listing dates per page HOT 1
- uninitialized constant custom field rails 7 HOT 3
- Changing date format HOT 3
- Option to disable form as "show" view? HOT 1
- My custom helper not is recognized HOT 2
- How i use concerns at trestle? HOT 1
- Remove Multiple Records From MODEL Page
- WebSockets / action_cable support? HOT 2
- Pagination for a custom index View
- Fix typo for Vietnamese locale HOT 1
- Direct upload or chunked file upload support? HOT 2
- Fails without sassc-rails
- Unable to locate favicon.ico in public folder HOT 1
- Best Way To Provide a Select Dropdown for belongs_to that is optional HOT 2
- Filter with a select list
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trestle.