Rails:没有路由匹配url的形式?

时间:2016-12-03 19:10:03

标签: ruby-on-rails ruby paperclip

我试图创建一个表单,用户可以使用paperclip gem上传文件。这是我到目前为止所得到的:

在new.html.erb中:

<%= form_for @replay, url: replay_path(@replay), :html => { :multipart => true } do |form| %>
    <%= form.file_field :r_file %>

    <%= form.submit "Submit" %>
<% end %>

这是我的重播控制器:

class ReplayController < ApplicationController
    def index
    end

    def new
        @replay = Replay.new
    end

    def create
        @replay = Replay.create(params[:replay])
        if @replay.save
            redirect_to @replay
        else
            render 'new'
        end
    end

    def show
        @replay = Replay.find(params[:id])
        #puts @replay.attachment.file_name
    end

    def update
    end

    private

    def replay_params
        params.require(:replay).permit(:r_file, :map)
    end
end

和我的路线:

  home_index GET    /home/index(.:format)      home#index
replay_index GET    /replay(.:format)          replay#index
             POST   /replay(.:format)          replay#create
  new_replay GET    /replay/new(.:format)      replay#new
 edit_replay GET    /replay/:id/edit(.:format) replay#edit
      replay GET    /replay/:id(.:format)      replay#show
             PATCH  /replay/:id(.:format)      replay#update
             PUT    /replay/:id(.:format)      replay#update
             DELETE /replay/:id(.:format)      replay#destroy
        root GET    /                          home#index

但是我在new.html.erb中的表单中收到以下错误:

No route matches {:action=>"show", :controller=>"replay", :id=>nil} missing required keys: [:id]

我不知道为什么:id是零?有什么想法吗?

0 个答案:

没有答案