Note that there are some explanatory texts on larger screens.

plurals
  1. PORails nested form with a "select" form element giving me "undefined method `merge' for #<ActiveSupport::SafeBuffer:0xb50d34b8>"
    text
    copied!<p>Background: My goal is for a view to display a list of "condition" has_many objects, which are themselves STI subclasses of a StateDescription. I want a user to be able to pick what type of state description they are from a drop down menu (which will conditionally display a different type of form, eventually)</p> <p>Inside of my main forms, I am doing a nested form like this:</p> <pre><code> &lt;%= f.fields_for :conditions do |e| %&gt; &lt;li&gt; &lt;%= e.select(:type, StateDescription.subclasses.collect{|x| x.to_s}, options_for_select(StateDescription.subclassSelectForms)) %&gt; &lt;br&gt; &lt;%= e.label :title %&gt; &lt;%= e.text_field :title %&gt; &lt;/li&gt; &lt;% end %&gt; </code></pre> <p>This works just fine with the text field at the bottom there (I can change values and save them, etc). But when I try to do a select statement, it explodes.</p> <p>Specifically, if I don't use e.select and just do:</p> <pre><code>&lt;%= select(:type, StateDescription.subclasses.collect{|x| x.to_s}, options_for_select(StateDescription.subclassSelectForms)) %&gt; </code></pre> <p>it renders just fine, but doesn't actually change any values as it is not associated with a model.</p> <p>If I get rid of trying to have it display a value different than it submits and just do</p> <pre><code>&lt;%= e.select(:type, StateDescription.subclasses.collect{|x| x.to_s}) %&gt; </code></pre> <p>Then it works just fine(I can submit, the value is saved to the database, I can retrieve it, etc).</p> <p>I can LEAVE it like this, but I had wanted to have my more human readable string display instead of a rails class thing (which might look like gibberish to a non-programmer end user). </p> <p><strong>So, my question is</strong>: Why do options_for_select break when nested and associated with a form, but dont' seem to when not associated with a form? Is it just a known bug? Am I doing something wrong?</p> <p>Edit:</p> <p>.subclasses is a standard rails calls which returns a list of subclasses for an object. </p> <p>.subclassSelect forms goes through each subclass, and turns it into a hash of the form:</p> <p>{subclass.to_s => subclass.human_readable_string} and compiles all of them into an array.</p> <p>I know this array of hashes works, because if I do NOT put "e" on the front, it displays correctly and works "right" for what I have done (i.e. the subclass is returned correctly based on which human readable string I select from the drop down menu, but since it's not actually associated with any form, it doesn't get set in the controller). </p>
 

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