2012-12-08 38 views
0

如何傳遞ID。我的控制器:如何傳遞控制器的ID

class AttachementsController < ApplicationController 
    def index 
    @pdf = Attachement.find(params[:resume_id]) 
    # send_file(@pdf.file.url, :type => 'application/pdf', :disposition => 'inline',:stream => false) 
    redirect_to @pdf.file.url 
    end 
end 

和控制器的我的測試情況是:

require 'spec_helper' 

describe AttachementsController do 

    describe "GET 'index'" do 
    it "should be successful" do 
     get 'index', :id => "@attachements.id" 
     response.should be_success 
    end 
    end 

end 

和我的錯誤是:

AttachementsController GET 'index' should be successful 
    Failure/Error: get 'index', :id => "@attachements.id" 
    ActiveRecord::RecordNotFound: 
     Couldn't find Attachement without an ID 
    # ./app/controllers/attachements_controller.rb:3:in `index' 
    # ./spec/controllers/attachements_controller_spec.rb:7:in `block (3 levels) in <top (required)>' 

回答

0

你不需要圍繞@attachements引號。 ID。

get 'index', :id => @attachements.id 
+0

他還可能需要:resume_id而不是:id – Phlip

相關問題