Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Admin: custom partial for belongs_to
    primarykey
    data
    text
    <p>I'm trying to create a custom partial for a has_many relationship and running into some issues.</p> <p>My models</p> <pre><code>Message has_many :formats Format belongs_to :message validates_inclusion_of :format_type, :in =&gt; FORMAT_TYPES.keys </code></pre> <p>I have a constant "FORMAT_TYPES" (wmv, flv, etc...) so that each "Format" record has a message_id and a format_type string that is in the allowed list.</p> <p>I'm trying to create a custom partial for rails_admin that allows the admin to use checkboxes to select which formats they want. Here's what I've got:</p> <pre><code>- for format in FORMAT_TYPES.keys %div = check_box_tag "message[formats][]", format = format </code></pre> <p>Which outputs this:</p> <pre><code>&lt;fieldset&gt; &lt;legend&gt;Formats&lt;/legend&gt; &lt;div&gt; &lt;input id="message_formats_" name="message[formats][]" type="checkbox" value="640x360_8"&gt; 640x360_8 &lt;/div&gt; &lt;div&gt; &lt;input id="message_formats_" name="message[formats][]" type="checkbox" value="480x272_8"&gt; 480x272_8 &lt;/div&gt; ... &lt;/fieldset&gt; </code></pre> <p>When I select a few formats and submit, I get this error:</p> <pre><code>ActiveRecord::AssociationTypeMismatch in RailsAdmin::MainController#create Format(#2196273220) expected, got String(#2151941320) </code></pre> <p>This sounds like it's expecting an existing Format id. Which makes me think I have to create a has_many_through and get rid of my constant. (trying to avoid that) </p> <p>Trying to figure out how to properly format my partial to allow the creation of these new Format records. Any ideas?</p> <p>Much thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload