I am working with a Rails 6.1 project and am using the twitter-bootstrap-rails gem to create a form using bootstrap_form_for for an object that has an association.
I would like to add the association fields to the form, and am finding that Rails has a fields_for, helper but I am not finding any equivalent in twitter-bootstrap-rails.
I was successfully using the fields_forhelper until I needed to create a form_group in it for radio buttons, where the data for the group is coming from an array of hashes.
Although the fields_forhelper does have the ability to create radio button groups, I am not seeing how to use a hash to populate the radio button fields.
How does one add form fields for an object's association, when using the twitter-bootstrap-rails gem maintaining the the full form_group capabilities?
If this isn't possible, can anyone point me to documentation on creating a radio button group under fields_for using an array of hashes as the data source?
Many thanks in advance for your suggestions.
Related
I have a PurchaseOrder Model that has_many Items. The form for PurchaseOrder needs variable input fields that will also save Items, where clicking the Add button will increase the fields in the page.
Here's what it will look like:
In order to achieve this:
How do I create a simple_form that will post the result of these multiple fields as an array to my existing PurchaseOrdercontroller where I can process and add these records?
Bonus: how would I handle this via Cucumber?
Edit: Why would you downvote a self contained question? Leave comments to explain when you downvote, please.
Use Cocoon as your nested forms for creating multiple fields.
You need to use simple_fields_for from simple_form gem. This allows you to work with attributes of associated models.
If you want to add new associated models via Add new button you need to create a new row. There is no code in pure simple_form that will help you with that. I found gem cocoon. It looks like it's what you're looking for. You can take a look how it's implemented there and make your own light solution.
How can I add dynamic fields to a rails form to create multiple objects from the same model? I'm able to do this with nested forms using the cocoon gem but for fields of the same model I can't figure it out. I tried to add fields dynamically trough js but without success! Can anyone point me on the right direction? Thanks.
My issue is simple, lets say I have two models/tables named 'abc' and 'pqr', both has three columns as 'a','b','c' in abc and 'p','q','r' in pqr. This two models may or may not be related/nested.
what I want to do is to create a single webpage. On that webpage I want to create a single form which will submit the data for two models/table with single button. May be I will create two form but I want only one submit button. How do solve this issue in ruby on rails.
As in rails we have one model per table.
You can only use accepts_nested_attributes_for if the two models are related. Otherwise, if the models are unrelated, see Anton's answer in rails: a single simple_form with two unrelated models? describing how to use the fields_for helper to accomplish this.
I can suggest you something in Ruby side. It is possible to do that with accepts_nested_attributes_for method.
You can add to
models/abc.rb
accepts_nested_attributes_for :pqr
You can find more information about it here.
http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
I'm using rails_admin with mongoid but seems this gem has no support for editing hash/array field types. it just put the content crashed inside a textarea.
anyone knows an admin tool that have support for this field types? maybe rails active_admin or another language?
you need display Hash object as Json that present in RailsAdmin datatypes
here is my PR
https://github.com/sferik/rails_admin/pull/3103
I want to add tags to a model and I also want those tags to be translatable to n languages.
I'm already using i18n gem to translate the contents. What's a proper way to implement translatable tags? Of course those tags will be created by different users.
The only way I thought about was to create a Tag model with {:id, :translation_id, :language, :name} using translation_id to link the tag to the original one.
Maybe the Globalize 3 gem could do the job for you.