title: How to upload photos in rails 4?
body: <p><a href="https://gist.github.com/Gtar69/27139cee82c75992ed82" rel="nofollow">https://gist.github.com/Gtar69/27139cee82c75992ed82</a></p>
  
  <p>Mac OS 10.9.3
  Rails 4.1.0 </p>
  
  <p>Now I want to add photo upload to my website ! In that way, in terminal=></p>
  
  <ol>
  <li>$ rails g model Photo image_name:string product:references </li>
  <li>$ rake db:migrate</li>
  <li>$ rails g migration add_image_to_photos image:string </li>
  <li>$ rake db:migrate </li>
  <li>$ rails g controller Photos</li>
  </ol>
  
  <p>Scheme as below:</p>
  
  <pre><code>ActiveRecord::Schema.define(version: 20140612034245) do
  
    create_table "photos", force: true do |t|
      t.string   "image_name"
      t.integer  "product_id"
      t.datetime "created_at"
      t.datetime "updated_at"
      t.string   "image"
    end
  
  
  
  config/routes.rb
  Rails.application.routes.draw do
    devise_for :users
      namespace :admin do 
        resources :products do
         resources :photos
        end 
    end 
  end
  
  
  
  For new created controller, PhotosController shown below" 
  
  class PhotosController &lt; ApplicationController
  
  
    def create
      @product = Product.find(params[:product_id])
        @photo = @product.photos.create(photo_params)
      redirect_to admin_product_path(@product)    
    end
  
    private
      def photo_params
        params.require(:photo).permit(:image_name, :iamge)
      end     
  end
  </code></pre>
  
  <p>Finally, adding "upload photos feature" in new.html.erb</p>
  
  <pre><code>&lt;div class="panel panel-default"&gt;
    &lt;div class="panel-body"&gt;
  
  &lt;%= simple_form_for [:admin, @product] do|f| %&gt;   
      &lt;div  class="group"&gt;
          &lt;%= f.input :title, label:'標題' %&gt;
      &lt;/div&gt;
  
      &lt;div class="group"&gt;
          &lt;%= f.input :description, label:'敘述'%&gt;  
      &lt;/div&gt;      
  
      &lt;div class = "group"&gt;
          &lt;%= f.input :quantity, label:'數量' %&gt;
      &lt;/div&gt;
  
      &lt;h2&gt;Add Photos&lt;/h2&gt;
      &lt;%= form_for([@product, @product.photos.build]) do |f| %&gt;
      &lt;% end %&gt;
      &lt;%= f.submit "Submit", :disable_with =&gt; 'Submiting...' %&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
             
  
  <p>However, I encounter the problem I can't understand =></p>
  
  <pre><code>  Rendered admin/products/new.html.erb within layouts/application (18.8ms)
  Completed 500 Internal Server Error in 57ms
  
  Showing /Users/Gtar/projects/artstore/app/views/admin/products/new.html.erb where line #26 raised:
  
  undefined method `product_photos_path' for #&lt;#&lt;Class:0x000001013b2ef8&gt;:0x00000101118670&gt;
  
  ActionView::Template::Error (undefined method `product_photos_path' for #&lt;#&lt;Class:0x000001013b2ef8&gt;:0x00000101118670&gt;):
      23:     &lt;/div&gt;  form_for([@article, @article.comments.build]) do |f| %&gt;
      24: --&gt;
      25:     &lt;h2&gt;Add Photos&lt;/h2&gt;
      26:     &lt;%= form_for([@product, @product.photos.build]) do |f| %&gt;
      27:     &lt;% end %&gt;
      28:     &lt;%= f.submit "Submit", :disable_with =&gt; 'Submiting...' %&gt;
      29:   &lt;/div&gt;
    app/views/admin/products/new.html.erb:26:in `block in _app_views_admin_products_new_html_erb__2984465001892677316_2165881840'
    app/views/admin/products/new.html.erb:8:in `_app_views_admin_products_new_html_erb__2984465001892677316_2165881840'
  </code></pre>
  
  <p>Would you mind helping me for solve the issure? </p>