小编two*_*ves的帖子

fill_in如何在Rspec/Capybara中运作?

我正在关注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方法需要输入字段和标签吗?

rspec ruby-on-rails capybara

12
推荐指数
2
解决办法
2万
查看次数

在轨道上的ruby中查找关联中的所有内容

在这里,我已经有了之间的1对多的关系ProductsUsers:

class Property < ActiveRecord::Base
  has_many :users
end

class User < ActiveRecord::Base
  belongs_to :property
end
Run Code Online (Sandbox Code Playgroud)

我怎样才能获得不属于任何用户的所有属性?

activerecord join ruby-on-rails include

5
推荐指数
2
解决办法
3126
查看次数

env配置文件中未初始化的常量ActiveSupport :: EventedFileUpdateChecker

我是Ruby on Rails的新手.运行'bundle'命令进行更新/安装后,当我尝试执行rails srails 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)

ruby-on-rails

5
推荐指数
2
解决办法
9885
查看次数

Rails范围与另一个模型范围连接?

在一种情况下,我需要加入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)

ruby ruby-on-rails

2
推荐指数
1
解决办法
2975
查看次数

标签 统计

ruby-on-rails ×4

activerecord ×1

capybara ×1

include ×1

join ×1

rspec ×1

ruby ×1