Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>your User model not attached to photos so photos only are belongs to Product model so you need to change your User model to be </p> <pre><code> class User &lt; ActiveRecord::Base has_many :products has_many :photos,:through=&gt;:products end </code></pre> <p>then you can fetch User photos through </p> <pre><code> @photos =current_user.photos </code></pre> <p>or you can build a photo easily </p> <pre><code>@photo = current_user.photos.build(params[:photo]) </code></pre> <p>also in your views you need to do instead of = f.file_field :photo, multiple: 'multiple'</p> <p>use </p> <pre><code>= fields_for :photos do |f_i| =f_i.file_field :image </code></pre> <p>try it .</p> <p>these is the simple way for has many through association </p> <pre><code> class Document &lt; ActiveRecord::Base has_many :sections has_many :paragraphs, :through =&gt; :sections end class Section &lt; ActiveRecord::Base belongs_to :document has_many :paragraphs end class Paragraph &lt; ActiveRecord::Base belongs_to :section end </code></pre> <p>you can check these guide for more info</p> <p><a href="http://guides.rubyonrails.org/association_basics.html" rel="nofollow">http://guides.rubyonrails.org/association_basics.html</a> also you need to put </p> <pre><code> accepts_nested_attributes_for :photos </code></pre> <p>inside your Product model</p> <p>for a complete tutorial about nested forms you can watch these screen cast </p> <p><a href="http://railscasts.com/episodes/196-nested-model-form-revised" rel="nofollow">http://railscasts.com/episodes/196-nested-model-form-revised</a></p> <p>its not free </p> <p>you can watch these free screen cast if your not subscribed to railscasts.com </p> <p><a href="http://railscasts.com/episodes/196-nested-model-form-part-1" rel="nofollow">http://railscasts.com/episodes/196-nested-model-form-part-1</a></p> <p><a href="http://railscasts.com/episodes/197-nested-model-form-part-2" rel="nofollow">http://railscasts.com/episodes/197-nested-model-form-part-2</a></p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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