title: Not able to get url from uploaded image, undefined method `url' error on has_many associated model
body: <pre><code>undefined method `url' for #&lt;GalleryPhoto:0x007f80c05a4ba8&gt;
  
  10:   &lt;%= @gallery.date %&gt;
  11: &lt;/p&gt;
  12: 
  13: &lt;%= @gallery.gallery_photos.first.url %&gt;
  14: 
  15: 
  16: &lt;%= link_to 'Edit', edit_gallery_path(@gallery) %&gt;
  </code></pre>
  
  <p>I am attempting to create a photo album system in a rails app where albums are created and images are uploaded to it via paperclip.  I am unable to get the .url method to work on my show page to display the image.  The way it is set up is like this:</p>
  
  <p>Gallery Model (has many gallery_photos)</p>
  
  <p>GalleryPhotos Model(belongs_to gallery)</p>
  
  <p>gallery show:</p>
  
  <pre><code>&lt;p id="notice"&gt;&lt;%= notice %&gt;&lt;/p&gt;
  
  &lt;p&gt;
    &lt;b&gt;Gallery name:&lt;/b&gt;
    &lt;%= @gallery.gallery_name %&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
    &lt;b&gt;Date:&lt;/b&gt;
    &lt;%= @gallery.date %&gt;
  &lt;/p&gt;
  
  &lt;%= @gallery.gallery_photos.first.url %&gt;
  
  
  &lt;%= link_to 'Edit', edit_gallery_path(@gallery) %&gt; |
  &lt;%= link_to 'Back', galleries_path %&gt;
  </code></pre>
  
  <p>gallery model</p>
  
  <pre><code>class Gallery &lt; ActiveRecord::Base
      attr_accessible :date, :gallery_name, :gallery_photos_attributes
      has_many :gallery_photos, :dependent =&gt; :destroy
  
      accepts_nested_attributes_for :gallery_photos
  
  end
  </code></pre>
  
  <p>gallery_photo model</p>
  
  <pre><code>class GalleryPhoto &lt; ActiveRecord::Base
      attr_accessible :photo, :caption, :date, :gallery_id
  
      belongs_to :gallery
  
      has_attached_file :photo,:styles =&gt; { :large =&gt; "300x300&lt;", :medium =&gt; "300x300&gt;", :thumb =&gt; "100x100&gt;" }, :default_url =&gt; "/images/:style/missing.png"
  
  end
  </code></pre>
  
  <p>Gallery controller</p>
  
  <pre><code>  def new
      @gallery = Gallery.new
      @gallery.gallery_photos.build # added this
    end
  
    def show
      @gallery = Gallery.find(params[:id])
    end
  
    def create
      @gallery = Gallery.new(params[:gallery])
  
      respond_to do |format|
        if @gallery.save!
          format.html { redirect_to @gallery, notice: 'Gallery was successfully created.' }
          format.json { render json: @gallery, status: :created, location: @gallery }
        else
          format.html { render action: "new" }
          format.json { render json: @gallery.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p>The table is mysql, and I am running this through a vagrant virtual system.  It is inserting on new, and it is making it. On new it is inserting data into the table for the galleries and for gallery_photos.  No matter what I do, I cannot get a url out of it.</p>