feature "comment" do
given(:user) do
build(:user)
end
background do
user1=create(:user)
user1.id=1
login_as(user1)
end
scenario "can create comment" do
@undertake=create(:undertake)
visit undertake_path(@undertake)
within("form#undertake-form-test") do
fill_in "content" , with: "heyheyhey"
end
click_button 'send-btn'
expect(page).to have_content 'heyheyhey'
end
end
Dies ist spec/features/comment_spec.rb. und das unten ist controllers/intrams_controller.rb.rspec, undefined Methode `id 'für nil: NilClass
class UndertakesController < ApplicationController
def show
@undertake=Undertake.find_by(id: params[:id])
@comment=current_user.comments.new
end
und das unten ist views/assists/show.html.erb.
<p><%= @undertake.id %></p>
und spec/fabriken/unconsents.rb.
FactoryGirl.define do
factory :undertake do
association :ask
association :user
id 1
user_id 2
ask_id 1
title "MyString"
content "MyText"
result false
end
end
routes.rb
resources :asks , except:[:edit, :update] do
resources :undertakes , only:[:create , :show , :destroy] , shallow: true do
resources :comments , only:[:create]
end
end
Nun, warum habe ich Fehler ActionView::Template::Error:undefined method id for nil:NilClass
. Bitte hilf mir.
Bitte zeigen Sie Ihre 'routes.rb' Datei an. –
Hier ist routes.rb. Bitte. –
Ressourcen: fragt, außer: [: edit,: update] do Ressourcen: übernimmt, nur: [: create,: show,: destroy], flach: true do Ressourcen: Kommentare, nur: [: create] Ende Ende –