在使用Ruby和Rails很长一段时间后,我想尝试RVM.一切正常,除了一件事:
在一个新开的终端ruby指向系统的红宝石,尽管事实上,我使用了rvm --default命令.
user@terra ~ $ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]
user@terra ~ $ which ruby
/opt/local/bin/ruby
user@terra ~ $ rvm list
ruby-1.8.7-p334 [ ]
=> ruby-1.9.2-p180 [ ]
Run Code Online (Sandbox Code Playgroud)
我打电话后一切都很好 rvm reload
user@terra ~ $ rvm reload
user@terra ~ $ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.1]
tmangner@terra ~ $ which ruby
/Users/user/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
Run Code Online (Sandbox Code Playgroud)
我.bash_profile按照文档中的描述设置了我:
[[ -s "/Users/user/.rvm/scripts/rvm" ]] && source "/Users/user/.rvm/scripts/rvm"
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.非常感谢.
我正在使用Mac OS X Snow Leopard(10.6.6)
更新:
这--default …
使用Capybara,我需要声明表单元素不存在,例如,'然后我不应该看到"用户名"文本字段'.如果找不到元素,find会抛出异常,这是我提出的最好的.有没有更好的办法?
Then /^I should not see the "([^\"]+)" ([^\s]+) field$/ do |name, type|
begin
# Capybara throws an exception if the element is not found
find(:xpath, "//input[@type='#{type}' and @name='#{name}']")
# We get here if we find it, so we want this step to fail
false
rescue Capybara::ElementNotFound
# Return true if there was an element not found exception
true
end
end
Run Code Online (Sandbox Code Playgroud)
我是Capybara的新手,所以我可能会遗漏一些明显的东西.
尝试安装gem设备时出错,安装停止在gem bcrypt-ruby上:
$ gem install bcrypt-ruby
Error installing bcrypt-ruby:
ERROR: Failed to build gem native extension.
Run Code Online (Sandbox Code Playgroud)
我在RVM下使用Ruby运行OSX 10.6.7.我重新安装了最新版本的xcode并重新安装了Ruby 64bit,Rails和所有宝石.
在Ruby 1.9.2堆栈跟踪中,我经常看到给出的方法<top (required)>,如下面的堆栈部分所示.这是什么意思?我的Ruby安装是否巧妙地破坏了?
Could not find abstract-1.0.0 in any of the sources
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:87:in `block in materialize'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:81:in `map!'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:81:in `materialize'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:90:in `specs'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:135:in `specs_for'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:124:in `requested_specs'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/environment.rb:23:in `requested_specs'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/runtime.rb:11:in `setup'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler.rb:107:in `setup'
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/setup.rb:14:in `<top (required)>'
<internal:lib/rubygems/custom_require>:33:in `require'
<internal:lib/rubygems/custom_require>:33:in `rescue in require'
<internal:lib/rubygems/custom_require>:29:in `require'
Run Code Online (Sandbox Code Playgroud) 我on Rails的3.0.7使用Ruby,我知道,在3.1版本中都不会有的auto_link方法了(见ActionPack的/ lib目录/ ACTION_VIEW /助理/ text_helper.rb的回报率3.1).
还有另一种方法可以使用与旧auto_link方法类似的功能吗?也就是说,我如何在Ruby on Rails 3.1中替换那个有用的方法?
顺便说一句:为什么这个auto_link方法会被删除?
我是测试Rails Web应用程序和RSpec的新手.我使用遗留代码并需要添加测试.那么使用RSpec测试查找器和命名范围的最佳方法是什么?
我在Google中找到了一些方法,但它们并不理想.例如:
http://paulsturgess.co.uk/articles/show/93-using-rspec-to-test-a-named_scope-in-ruby-on-rails
it "excludes users that are not active" do
@user = Factory(:user, :active => false)
User.active.should_not include(@user)
end
Run Code Online (Sandbox Code Playgroud)
要么
http://h1labs.com/notebook/2008/8/21/testing-named-scope-with-rspec
it "should have a published named scope that returns ..." do
Post.published.proxy_options.should == {:conditions => {:published => true}}
end
Run Code Online (Sandbox Code Playgroud)
我在"铁路测试处方"中找到最佳方法(恕我直言):
should_match_find_method :active_only { :active == true }
Run Code Online (Sandbox Code Playgroud)
哪里有should_match_find_method自定义助手方法
这很简单,我不敢相信它抓住了我.
def meth(id, options = "options", scope = "scope")
puts options
end
meth(1, scope = "meh")
-> "meh"
Run Code Online (Sandbox Code Playgroud)
我倾向于使用哈希作为参数选项,因为它是牧群的做法 - 它非常干净.我认为这是标准.今天,经过大约3个小时的寻找bug之后,我追踪到了一个错误,我碰巧正在使用这个假设命名参数将被尊重.他们不是.
所以,我的问题是:在Ruby(1.9.3)中,命名参数是否正式不受尊重,或者这是我缺少的一个副作用?如果他们不是,为什么不呢?
def new
before_filter do
redirect_to "/" unless current_admin || current_company
flash[:notice] = 'You dont have enough permissions to be here' unless current_admin || current_company
end
CODE CODE CODE
end
def edit
before_filter do
redirect_to "/" unless current_admin.id = 5
flash[:notice] = 'You dont have enough permissions to be here' unless current_admin || current_company
end
CODE CODE CODE
end
Run Code Online (Sandbox Code Playgroud)
这是我想要做的代码,但我无法弄清楚如何正确地做到这一点.我想要实现的是为我的每个动作应用before_filter规则.因此,或许用户可以存取权限去INDEX行动,但不会在修改动作等我知道的before_filter方法运行一个单一的时间,我不能跑4个before_filters,我只是给的,因为我的英语不好一些参考.
您必须知道我正在使用Devise作为current_admin和current_company方法.我需要应用不同的过滤器(如果是admin或者如果是company.id = X)和其他操作.
在此先感谢,我非常喜欢这里.任何帮助将不胜感激.
由于法拉第没有文件,我无法在任何地方找到它.什么是"超时"以及法拉第中的"开启超时"?
错误:
/Users/askar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mysql2-0.3.20/lib/mysql2.rb:31:in `require': dlopen(/Users/askar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/mysql2-0.3.20/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/lib/libmysqlclient.18.dylib (LoadError)
Referenced from: /Users/askar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/mysql2-0.3.20/mysql2/mysql2.bundle
Reason: image not found - /Users/askar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/mysql2-0.3.20/mysql2/mysql2.bundle
Run Code Online (Sandbox Code Playgroud)
在Gemfile中: gem 'mysql2'
$ ls -al/usr/local/lib/libmysql*
lrwxr-xr-x 1 askar admin 49 Nov 13 10:48 /usr/local/lib/libmysqlclient.20.dylib -> ../Cellar/mysql/5.7.9/lib/libmysqlclient.20.dylib
lrwxr-xr-x 1 askar admin 42 Nov 13 10:48 /usr/local/lib/libmysqlclient.a -> ../Cellar/mysql/5.7.9/lib/libmysqlclient.a
lrwxr-xr-x 1 askar admin 46 Nov 13 10:48 /usr/local/lib/libmysqlclient.dylib -> ../Cellar/mysql/5.7.9/lib/libmysqlclient.dylib
lrwxr-xr-x 1 askar admin 37 Nov 13 10:48 /usr/local/lib/libmysqld.a -> ../Cellar/mysql/5.7.9/lib/libmysqld.a
lrwxr-xr-x 1 askar admin 44 Nov 13 10:48 /usr/local/lib/libmysqlservices.a -> ../Cellar/mysql/5.7.9/lib/libmysqlservices.a …Run Code Online (Sandbox Code Playgroud)