【发布时间】:2017-10-26 03:29:18
【问题描述】:
我正在尝试解决一个挑战,但我收到了来自 Cabybara 的错误消息:
`Failure/Error: fill_in 'Name', with: 'Vostro 2017'
Capybara::ElementNotFound: Unable to find visible field "Name" that is not disabled`
我的new.html.erb 是:
<%= form_for @item, url: {action: "create"} do |f|%>
<%= f.label 'Name' %>
<%= f.text_field :name %>
<%= f.label 'Description' %>
<%= f.text_field :description %>
<%= f.label 'Features' %>
<%= f.text_field :features %>
<%= f.label 'Asset number' %>
<%= f.text_field :assetNumber %>
<%= f.submit%>
<% end %>
而我的item_controller.rb 是:
class ItemController < ApplicationController
def show
@items = Item.find(params[:id])
end
def new
@item = Item.new
end
def create
@item = Item.new(item_params)
@item.save
redirect_to @item
end
private
def item_params
params.require(:item).permit(:name, :description, :features, :assetNumber)
end
end
用于进行测试的 rspec 文件是:
require 'rails_helper'
feature 'User creates a new inventory item' do
scenario 'successfully' do
visit new_item_path
fill_in 'Name', with: 'Vostro 2017'
fill_in 'Description', with: 'Dell Notebook'
fill_in 'Features', with: '16gb, 1Tb, 15.6"'
fill_in 'Asset number', with: '392 DLL'
click_button 'Create Item'
expect(page).to have_content 'Vostro 2017'
expect(page).to have_content 'Dell Notebook'
expect(page).to have_content '16gb, 1Tb, 15.6"'
expect(page).to have_content '392 DLL'
end
end
我正在使用 ruby-2.3.5 和 rails 4.1.0。 我是 ruby/rails 的初学者,我不知道我的代码有什么问题。 有人可以帮我解决这个问题吗? 我提前感谢。
【问题讨论】:
-
你能否用模态更新问题。
-
@Ziyan Junaideen 什么是模态?
标签: ruby-on-rails ruby rspec capybara