我正在关注Michael Hartl的Ruby on Rails教程.当我使用rspec/capybara时,fill_in方法让我感到困惑.我有以下视图代码:
<%= f.label :name %>
<%= f.text_field :name %>
Run Code Online (Sandbox Code Playgroud)
这是我的测试代码:
fill_in "Name", with: "Example User"
Run Code Online (Sandbox Code Playgroud)
fill_in似乎都需要label和text_field来定位输入字段.如果我要么起飞f.label或更改 <%= f.text_field :name %>是<%= f.text_field :another_name %>,测试会给我ElementNotFound的错误.任何人都可以解释fill_in如何在这里工作?fill_in方法需要输入字段和标签吗?
在这里,我已经有了之间的1对多的关系Products和Users:
class Property < ActiveRecord::Base
has_many :users
end
class User < ActiveRecord::Base
belongs_to :property
end
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得不属于任何用户的所有属性?
我是Ruby on Rails的新手.运行'bundle'命令进行更新/安装后,当我尝试执行rails s或rails g mongoid:config控制台返回此消息时,该消息以:
/home/myUser/proyect/config/environments/development.rb:50:in `block in <top (required)>': uninitialized constant ActiveSupport::EventedFileUpdateChecker (NameError)
Run Code Online (Sandbox Code Playgroud)
这是我的Gemfile(是的,我想使用MongoDB作为数据库):
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Mongoid as the database
gem 'mongoid', '~> 5.1.0'
# Use bson
gem 'bson_ext'
# Use Puma as the app server
gem 'puma', '~> 3.0'
#Use Haml for html
gem 'haml'
# Use SCSS …Run Code Online (Sandbox Code Playgroud) 在一种情况下,我需要加入4个范围中的4个范围,3个是用模型(A)编写的,另一个是模型(B),如何加入这些范围?
这两个模型有HABTM关系
Model A
scope 1
scope 2
scope 3
total_scope= scope1.scope2.scope3.scope4
end
Model B
scope 4
end
Run Code Online (Sandbox Code Playgroud)