当我运行rspec
与rake rspec
和我的测试是不正常的,我得到一个错误信息.但是,当我的测试没问题时,我就得到'..'.没有其他输出.我怎样才能打印出类似的内容:
A User .... can only have one name
A User .... can ...
Run Code Online (Sandbox Code Playgroud) 我想建立一个HashSet<u8>
来自Vec<u8>
.我想这样做
2n
记忆,但我唯一可以编译的就是这段...垃圾,我认为这两次复制数据并使用3n
内存.
fn vec_to_set(vec: Vec<u8>) -> HashSet<u8> {
let mut victim = vec.clone();
let x: HashSet<u8> = victim.drain(..).collect();
return x;
}
Run Code Online (Sandbox Code Playgroud)
我希望写一些简单的东西,比如:
fn vec_to_set(vec: Vec<u8>) -> HashSet<u8> {
return HashSet::from_iter(vec.iter());
}
Run Code Online (Sandbox Code Playgroud)
但那不会编译:
error[E0308]: mismatched types
--> <anon>:5:12
|
5 | return HashSet::from_iter(vec.iter());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u8, found &u8
|
= note: expected type `std::collections::HashSet<u8>`
= note: found type `std::collections::HashSet<&u8, _>`
Run Code Online (Sandbox Code Playgroud)
..我真的不明白错误信息,可能是因为我需要RTFM.
当我运行我的功能规范时,我收到此消息:
弃用警告:不推荐使用ActiveRecord :: Base.raise_in_transactional_callbacks =,无效,将在不更换的情况下删除.
我正在使用Rails 5.0.0.rc1,我不确定是什么抛出了这个弃用警告.
我在我的application.rb
文件中有这个.我删除了它,弃用警告消失了:
config.active_record.raise_in_transactional_callbacks = true
Run Code Online (Sandbox Code Playgroud)
我想知道这个弃用警告实际意味着什么,并知道什么触发了这个弃用警告.
我想要一个更新资源的链接,而不使用HTML表单.
路线:
resources :users do
resource :profile, :controller=>"profiles"
resources :friends
end
Run Code Online (Sandbox Code Playgroud)
耙路线:
user_friend GET /users/:user_id/friends/:id(.:format){:action=>"show", :controller=>"friends"}
PUT /users/:user_id/friends/:id(.:format){:action=>"update", :controller=>"friends"}
Run Code Online (Sandbox Code Playgroud)
我想通过简单的链接使用put来更新朋友,如下所示:
<%= link_to"Add as friend",user_friend_path(current_user,:method =>'put')%>
但是当Rails遇到这个链接时,他试图进入节目动作.
问题是:这样做的正确链接是什么?
给定查询对象(不是AR模型)
class ComplexQuery
QUERY = <<-SQL
...
SQL
def new(param1, param2)
...
end
def execute
# format and interpolate parameters into QUERY
# pass finished SQL to `execute` or `select_all`
end
end
Run Code Online (Sandbox Code Playgroud)
我怎样才能方便地逃避所有参数?
我已经成功完成了三种技术,但没有一种方便.
raw_connection
which(对我来说)返回一个实例PG::Conn
并调用exec_params
.我对此不满意,因为exec_params
需要一组冗长的参数来指定数据类型.include ActiveRecord::Sanitization
在我的查询对象中,并使用其中一个方便的方法,如replace_named_bind_variables
.我并不满足于此,因为replace_named_bind_variables
是protected
我必须使用send
. module
代替.出于某种原因,当我include ActiveRecord::Sanitization
进入模块时,我能够使用其受保护的方法.我对此不满意,因为我想有时不执行它来实例化我的查询对象,例如用于测试.包括ActiveRecord::Sanitization
成class
像的最佳解决方案感觉,但我必须做一些错误的,因为我应该能够使用protected
方法.
我正在寻找一个解决方案:
我能够找到一些相关的问题
我想用QT5的QtWebKit
用capybara-webkit
.
brew uninstall qt
Uninstalling /usr/local/Cellar/qt/4.8.4...
brew install qt5
This formula is keg-only: so it was not symlinked into /usr/local.
/usr/local/Cellar/qt5/5.0.2: 3103 files, 140M, built in 60.9 minutes
Run Code Online (Sandbox Code Playgroud)
如果我强制brew为qt5创建符号链接,我可以为capybara-webkit
... 构建本机扩展名.
brew link --force qt5
Linking /usr/local/Cellar/qt5/5.0.2... 122 symlinks created
gem install capybara-webkit -v '1.0.0'
Successfully installed capybara-webkit-1.0.0
Run Code Online (Sandbox Code Playgroud)
..但webkit_server
很难崩溃..
bundle exec rake test:integration
Errno::EADDRNOTAVAIL: Can't assign requested address - connect(2)
dyld: Library not loaded: /private/tmp/qt5-KytU/qt-everywhere-opensource-src-5.0.2/qtwebkit/lib/QtWebKit.framework/Versions/5/QtWebKit
Referenced from: /usr/local/opt/qt5/lib/QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets
Reason: image not found
Run Code Online (Sandbox Code Playgroud)
查看 …
我在创建 ruby on Rails 项目时遇到错误。rails new club
在命令中,我通过键入,然后键入 来创建一个新项目bundle
。现在,当我尝试通过键入并输入 创建模型和控制器时rails g resource Club name
,我收到此错误:superclass mismatch for class StringIO (TypeError)
。
gems/bootsnap-1.9.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:
in `require': superclass mismatch for class StringIO (TypeError)
Run Code Online (Sandbox Code Playgroud)
我什至没有名为 的类StringIO
,所以我不确定它来自哪里。
我相信rails生产的默认行为是不输出所有部分的渲染.这应该登录开发而不是生产.
但是,我在制作中看到了这一点,我不知道如何删除它.我的日志太吵了.我的生产环境是Heroku运行Unicorn并使用Papertrail查看我的日志.我知道Unicorn用日志做了一些不稳定的东西,并且为了让它们正常工作,我必须将它添加到我的production.rb:
config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get('INFO')
Run Code Online (Sandbox Code Playgroud)
(在此解释:http://help.papertrailapp.com/kb/configuration/unicorn)
但即使使用log_level INFO,我在所有日志中都看到了大量的这些:
Jun 25 22:15:15 tacktile app/web.1: Rendered photos/pieces/_caption.html.erb (0.7ms)
Jun 25 22:15:15 tacktile app/web.1: Rendered photos/pieces/_rights.html.erb (2.1ms)
Jun 25 22:15:15 tacktile app/web.1: Rendered photos/pieces/_category.html.erb (4.8ms)
Jun 25 22:15:15 tacktile app/web.1: Rendered photos/pieces/_caption.html.erb (0.3ms)
Jun 25 22:15:15 tacktile app/web.1: Rendered photos/pieces/_rights.html.erb (0.4ms)
Jun 25 22:15:15 tacktile app/web.1: Rendered photos/pieces/_category.html.erb (4.4ms)
Jun 25 22:15:15 tacktile app/web.1: Rendered photos/pieces/_caption.html.erb (0.3ms)
Jun 25 22:15:15 tacktile app/web.1: Rendered photos/pieces/_rights.html.erb (0.3ms)
Jun …
Run Code Online (Sandbox Code Playgroud) 我有一个使用两者的模型:Carrierwave用于商店照片和PaperTrail
版本控制.
我还在更新时配置了Carrierwave用于存储不同的文件(那是因为我想对照片进行版本控制) config.remove_previously_stored_files_after_update = false
问题是PaperTrail
尝试从照片(CarrierWave Uploader)存储整个Ruby对象而不是简单的字符串(这将是它的url)
(版本表,列对象)
---
first_name: Foo
last_name: Bar
photo: !ruby/object:PhotoUploader
model: !ruby/object:Bla
attributes:
id: 2
first_name: Foo1
segundo_nombre: 'Bar1'
........
Run Code Online (Sandbox Code Playgroud)
如何修复此问题以在照片版本中存储简单的字符串?