如何传递控制器的id

时间:2012-12-08 06:45:34

标签: ruby-on-rails-3 rspec-rails

如何传递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)>'

1 个答案:

答案 0 :(得分:0)

你不需要@ attachements.id周围的引号。

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