I am getting the following error from a RSpec get request:
1) Flight GET/index displays flights
Failure/Error: Unable to find matching line from backtrace
NoMethodError:
undefined method `request=' for #<Flight:0x00000006a2ad68>
這是我的規格/請求/ flights_spec.rb:RSpec的未定義的方法`請求=」
require 'rails_helper'
require 'spec_helper'
require 'flight'
RSpec.describe Flight, type: :controller do
describe 'GET/index', :type => :request do
it 'displays flights' do
Flight.create!(:destination => 'San Francisco')
get :index
response.body.should include('San Francisco')
end
end
end
這是我的規格/控制器/ flights_controller_spec.rb:
require 'rails_helper'
RSpec.describe FlightsController, type: :controller do
describe 'GET index' do
end
end
這裏是我的應用程序/ controllers/flights_controller.rb:
class FlightsController < ApplicationController
before_action :set_flight, only: [:show, :edit, :update, :destroy]
# GET /flights
# GET /flights.json
def index
@flights = Flight.all
end
# GET /flights/1
# GET /flights/1.json
def show
end
# GET /flights/new
def new
@flight = Flight.new
end
# GET /flights/1/edit
def edit
end
# POST /flights
# POST /flights.json
def create
@flight = Flight.new(flight_params)
respond_to do |format|
if @flight.save
format.html { redirect_to @flight, notice: 'Flight was successfully created.' }
format.json { render :show, status: :created, location: @flight }
else
format.html { render :new }
format.json { render json: @flight.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /flights/1
# PATCH/PUT /flights/1.json
def update
respond_to do |format|
if @flight.update(flight_params)
format.html { redirect_to @flight, notice: 'Flight was successfully updated.' }
format.json { render :show, status: :ok, location: @flight }
else
format.html { render :edit }
format.json { render json: @flight.errors, status: :unprocessable_entity }
end
end
end
# DELETE /flights/1
# DELETE /flights/1.json
def destroy
@flight.destroy
respond_to do |format|
format.html { redirect_to flights_url, notice: 'Flight was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_flight
@flight = Flight.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def flight_params
params.require(:flight).permit(:departure, :arrival, :destination, :baggage_allowance, :capacity)
end
end
不知道發生了什麼鑼上 - 任何幫助讚賞 - 在此先感謝, 斯拉夫科
您可能在此處未顯示代碼中的某處出現'@flight.request ='。也許在一個視圖? – infused