title: Missing required key :id on new photo form
body: <p>I have <strong>Photo</strong> model which belongs to <strong>User</strong> model. Rails returns this error whenever I try to access new view for <code>/users/4/photos/new</code>:</p>
  
  <pre><code>No route matches {:action=&gt;"index", :controller=&gt;"photos", :user_id=&gt;"4"} missing required keys: [:id]
  </code></pre>
  
  <p>This is my <em>PhotosController</em>:</p>
  
  <pre><code>class PhotosController &lt; ApplicationController
      def index
          find_user
          @photos = @user.photos
      end
  
      def new
          find_user
          @photo = @user.photos.build
      end
  
      def show
          find_photo
      end
  
      def create
          @photo = Photo.new(params[:photo])
  
          if @photo.save
  
              if params[:images]
                  params[:images].each { |image|
                      @user.photos.create(image: image)
                  }
              end
  
          else
              render 'new'
          end
      end
  
      def update
          find_user
          @photo = @user.photos.find(params[:id])
  
          if @photo.update
              redirect_to photos_path
          else
              render 'edit'
          end
      end
  
      def destroy
          find_photo
          @photo.destroy
  
          redirect_to photos_path
      end
  
      private
  
      def find_user
          @user = User.find(params[:user_id])
      end
  
      def find_photo
          @photo = Photo.find(params[:id])
      end
  
      def photo_params
          require(:photo).permit(:title, :image, :user_id)
      end
  end
  </code></pre>
  
  <p>And this is my <em>_form</em> partial for photos views.</p>
  
  <pre><code>&lt;%= form_for @photo, :html =&gt; { class: 'form-horizontal', multipart: true } do |f| %&gt;
  &lt;%= f.label :title %&gt;
  &lt;%= f.text_field :title, class: "input-field form-control" %&gt;
  
  &lt;%= f.label :pictures %&gt;
  &lt;%= file_field_tag "images[]", type: :file, multiplue: true %&gt;
  
  &lt;%= f.submit nil, class: "btn btn-primary" %&gt;
  </code></pre>
  
  
  
  <p>I don't understand how ID is missing, I'm providing it via <em>find_user</em> method.</p>
  
  <p>Update:</p>
  
  <pre><code># routes.rb
  Rails.application.routes.draw do
  
    root 'welcome#index'
  
    # prevedene rute
    get "/pocetna"          =&gt; "welcome#index", as: "index" 
    get "/o-sajtu"          =&gt; "welcome#about", as: "about"
    get "/moj-profil"       =&gt; "users#show", as: "profile"
    post "/users"         =&gt; "users#create"
    get "/users"          =&gt; "users#index", as: "users"
    get "/user"           =&gt; "users#index"
    get "/users/:id"       =&gt; "users#show", as: "user"
    get "/users/:id/edit" =&gt; "users#edit", as: "edit_user"
    patch "/users/:id"     =&gt; "users#update"
    get "/users/add"    =&gt; "users#new", as: "new_user"
  
    resources :sessions, only: [:new, :create, :destroy]
  
    get "/login"   =&gt; "sessions#new", as: "login"
    post "/login"  =&gt; "sessions#create"
    get "/logout"    =&gt; "sessions#destroy", as: "logout"
    delete "/logout" =&gt; "sessions#destroy"
  
    resources :users do
      resources :photos
    end
  end
  </code></pre>
  
  <p><strong>Update</strong>
  I get new error now</p>
  
  <pre><code>undefined method `photos_path' for #&lt;&lt;Class:0x007f4f14f16160&gt;:0x00000004f040e8&gt;
  </code></pre>
  
  <p>First line of the form is marked.</p>