或者是生成随机和唯一用户名所必需的外部gem?
这是我目前的工厂:
factory :user_4 do
sequence(:id) { |n| n }
sequence(:first_name) { |n| "Gemini" + n.to_s }
sequence(:last_name) { |n| "Pollux" + n.to_s }
sequence(:profile_name) { |n| "GeminiPollux" + n.to_s }
sequence(:email) { |n| "geminipollus" + n.to_s + "@hotmail.co.uk" }
end
Run Code Online (Sandbox Code Playgroud)
使用序列方法适用于id,profile_name和email,但我的REGEX验证意味着名字和姓氏自动无效,因为它们中有一个数字.与独特性无关.
那么我该如何创建这些独特的名字呢?
我有最新版本的curl,仍然没有看到http2显示为一个功能.我已经按照相关问题的步骤,但仍然运气不好.
$ /usr/local/Cellar/curl/7.43.0/bin/curl -V
curl 7.43.0 (x86_64-apple-darwin14.3.0) libcurl/7.43.0 SecureTransport zlib/1.2.5
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL libz UnixSockets
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
当我运行ruby时script/server -e test,它在控制台上运行.当我关闭控制台时,它也会停止该过程.我想在后台运行服务器.我怎样才能做到这一点?
我在Ruby中有一个字符串变量,如下所示:
puts $varString.class
puts "##########"
puts $varString
Run Code Online (Sandbox Code Playgroud)
上面代码的输出是:
String
##########
my::FIrst::Line
this id second line
sjdf kjsdfh jsdf
djsf sdk fxdj
Run Code Online (Sandbox Code Playgroud)
我只需要从字符串变量中获取第一行(例如my::FIrst::Line).我怎么才能得到它?
一切都在本地工作正常,但当我尝试推送到heroku时我得到了错误:
正在运行:rake assets:预编译
Run Code Online (Sandbox Code Playgroud)Connecting to database specified by DATABASE_URL rake aborted! could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?/tmp/build_1903c764-07ce-4d06-aa45-6e78dec68af8/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in`initialize'
Run Code Online (Sandbox Code Playgroud)/tmp/build_1903c764-07ce-4d06-aa45-6e78dec68af8/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `new'......等
我怀疑它必须对database.yml做一些事情,所以这里是:
development:
adapter: mysql2
encoding: utf8
database: dev-db
pool: 5
timeout: 5000
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
database: test-db
pool: 5
timeout: 5000
socket: /tmp/mysql.sock
production:
adapter: postgresql
encoding: utf8
database: prod-db
pool: 5
timeout: 5000
# socket: /tmp/mysql.sock
Run Code Online (Sandbox Code Playgroud) 我有一个Blog应用程序可以使用的可安装引擎.
允许使用引擎的应用程序设置配置变量site_name(以便引擎可以在设计中显示)的最佳方法是什么?
更新:
我见过一些宝石创建了'config/initializers/gem_name.rb'文件.有没有关于如何:
我尝试Blog.site_name = "My Site"在应用程序的config/initializers/blog.rb文件中创建,但得到一个未定义的方法错误.
我刚刚更新了所有的宝石,我发现在尝试运行Test :: Unit测试时我遇到了错误.我收到下面复制的错误.这来自于创建新的空Rails项目,搭建一个简单的模型和运行rake test.
尝试谷歌搜索"未初始化的常量"和TestResultFailureSupport.我发现的唯一一件事是2007年的这个错误报告.
我正在使用OS X.
这些是我在测试停止工作之前更新的宝石:
$ sudo gem outdated
Password:
RedCloth (4.2.1 < 4.2.2)
RubyInline (3.8.1 < 3.8.2)
ZenTest (4.1.1 < 4.1.3)
bluecloth (2.0.4 < 2.0.5)
capistrano (2.5.5 < 2.5.8)
haml (2.0.9 < 2.2.1)
hoe (2.2.0 < 2.3.2)
json (1.1.6 < 1.1.7)
mocha (0.9.5 < 0.9.7)
rest-client (1.0.2 < 1.0.3)
thoughtbot-factory_girl (1.2.1 < 1.2.2)
thoughtbot-shoulda (2.10.1 < 2.10.2)
Run Code Online (Sandbox Code Playgroud)
还有其他人看过这个问题吗?任何疑难解答建议
在预感中,我将ZenTest从4.1.3降级回4.1.1现在一切都恢复正常.
仍然很想知道是否有其他人看过这个或有任何有趣的评论或见解.
$ rake test
(in /Users/me/foo)
/usr/local/bin/ruby -I"lib:test" "/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/unit/helpers/users_helper_test.rb" "test/unit/user_test.rb"
/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:105:in …Run Code Online (Sandbox Code Playgroud) 我在使用旧的Ruby on Rails 2应用程序时遇到问题,该应用程序在一年内没有工作.
我正试图rake test:functionals在我的项目目录的根目录中运行,但是我得到了undefined method 'name' for "SystemTimer":String.
我已经粘贴了我认为与此问题相关的所有内容:http: //pastebin.com/NgBvystZ
此外,当我自己运行rake时,我
Errors running test:units!
不知道如何调试它.
我复制并粘贴了一些我认为对理解这个问题有用的东西.非常感谢您的时间.谢谢.
我有以下路线删除/列出用户.
map.connect 'developer/:user_name/delete',:controller=>"developers",:action=>"delete",:method=>:delete
map.connect 'developer/:user_name/list',:controller=>"developers",:action=>"list",:method=>:get
Run Code Online (Sandbox Code Playgroud)
在通过使用%2E编码Dot来列出用户时,我可以看到成功响应
http://localhost:3000/developer/testuser%2Ehu/list
Run Code Online (Sandbox Code Playgroud)
但在尝试删除包含Dot(.)的用户时,会抛出404错误.
http://localhost:3000/developer/testuser%2Ehu/delete, how to fix this issue.
Run Code Online (Sandbox Code Playgroud) 我有一个简单的设置User和UserProfile模型与User has_one :user_profile和UserProfile belongs_to :user.
但我无法理解Rails如何定义after_create回调的执行顺序并accepts_nested_attributes_for在我的模型中定义.让我们考虑这两种情况.
情况1:
class User < ActiveRecord::Base
has_one :user_profile
accepts_nested_attributes_for :user_profile
after_create :test_test
end
Run Code Online (Sandbox Code Playgroud)
现在,如果我通过控制台创建用户(也使用user_profile_attributes哈希),after_create则会在创建用户及其用户配置文件后触发回调.
案例2:
如果after_create放在顶部,
class User < ActiveRecord::Base
after_create :test_test
has_one :user_profile
accepts_nested_attributes_for :user_profile
end
Run Code Online (Sandbox Code Playgroud)
在创建用户之后但在创建用户配置文件之前触发回调.
这是它预期运作的方式.Rails在这里做什么?执行顺序是否仅由代码的顺序决定?
我在哪里开始深入研究或调试这个?
ruby ×5
after-create ×1
callback ×1
curl ×1
factory-bot ×1
heroku ×1
homebrew ×1
http2 ×1
testing ×1