Note that there are some explanatory texts on larger screens.

plurals
  1. POhas_many record insertion
    text
    copied!<p>I want to insert tags in new Place. giving that tags is in different model. </p> <pre><code>####### models ########## class Tag &lt; ActiveRecord::Base belongs_to :place attr_accessible :tag end class Place &lt; ActiveRecord::Base has_many :tags end </code></pre> <p>how can I handle this in the new Place create form? and the create action in the places_controller? so that I can insert new place and mant tags then assign the product id to each tag.</p> <pre><code>####### place controller ########## def create @place = Place.new(params[:place]) @tag = Tag.new(params[:?????]) #this should be more than once respond_to do |format| if @place.save format.html { redirect_to @place, notice: 'Place was successfully created.' } format.json { render json: @place, status: :created, location: @place } else format.html { render action: "new" } format.json { render json: @place.errors, status: :unprocessable_entity } end end end ####### place new form ########## &lt;%= form_for @place do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.label :title %&gt;&lt;br /&gt; &lt;%= f.text_field :title %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :description %&gt;&lt;br /&gt; &lt;%= f.text_area :description %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :rank %&gt;&lt;br /&gt; &lt;%= f.text_field :rank %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :lat %&gt;&lt;br /&gt; &lt;%= f.text_field :lat %&gt; &lt;/div&gt;&lt;div class="field"&gt; &lt;%= f.label :lng %&gt;&lt;br /&gt; &lt;%= f.text_field :lng %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :address %&gt;&lt;br /&gt; &lt;%= f.text_area :address %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :website %&gt;&lt;br /&gt; &lt;%= f.text_field :website %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :phone %&gt;&lt;br /&gt; &lt;%= f.text_field :phone %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= label_tag "tags" %&gt; &lt;%= f.text_field :tag %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre>
 

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