Note that there are some explanatory texts on larger screens.

plurals
  1. POaccepts_nested_attributes_for: What am I doing wrong
    text
    copied!<p>I try do create a one-to-many connection in rails4. However, although I don't get an error, the nested attribute is not stored.</p> <p>What am I doing wrong?</p> <p><strong>Station-Models</strong></p> <pre><code>class Station &lt; ActiveRecord::Base has_many :adresses accepts_nested_attributes_for :adresses end </code></pre> <p><strong>Adress-Model</strong></p> <pre><code> class Adress &lt; ActiveRecord::Base belongs_to :station end </code></pre> <p><strong>Station-Controller</strong> class StationsController &lt; ApplicationController</p> <pre><code> def new @station = Station.new @station.adresses.build end def create @station = Station.new(station_params) @station.save redirect_to @station end def index @stations = Station.all end private def station_params params.require(:station).permit(:name, adresses_attributes: [ :url ]) end end </code></pre> <p><strong>Station: new.html.erb</strong></p> <pre><code>&lt;%= form_for :station, url: stations_path do |station| %&gt; &lt;p&gt; &lt;%= station.label :name %&gt;&lt;br /&gt; &lt;%= station.text_field :name %&gt; &lt;/p&gt; &lt;%= station.fields_for :adresses do |adress| %&gt; &lt;div class="field"&gt; &lt;p&gt; &lt;%= adress.label :url %&gt;&lt;br /&gt; &lt;%= adress.text_field :url %&gt; &lt;/p&gt; &lt;/div&gt; &lt;% end %&gt; &lt;p&gt; &lt;%= station.submit %&gt; &lt;/p&gt; &lt;% end %&gt; </code></pre> <p>[edit]<br> I constructed a minimal example of this problem and documented it as a step-by-step instruction here: <a href="https://groups.google.com/forum/#!topic/rubyonrails-talk/4RF_CFChua0" rel="noreferrer">https://groups.google.com/forum/#!topic/rubyonrails-talk/4RF_CFChua0</a></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