小编Sha*_*oke的帖子

了解Gemfile.lock文件

运行该bundle install命令后,将在工作目录中创建"Gemfile.lock ".该文件中的指令是什么意思?

例如,让我们采取以下文件:

PATH
  remote: .
  specs:
    gem_one (0.0.1)

GEM
  remote: http://example.org/
  specs:
    gem_two (0.0.2)
    gem_three (0.0.3)
      gem_four (0.0.4)

PLATFORMS
  platform

DEPENDENCIES
  gem_two
  gem_one!
Run Code Online (Sandbox Code Playgroud)

' PATH ',' GEM ',' PLATFORMS '和' DEPENDENCIES '描述的是什么?他们都需要吗?

什么应该包含' 远程 '和' 规格 '子命令?

" DEPENDECIES "组中宝石名称后的感叹号是什么意思?

ruby bundler gemfile.lock

174
推荐指数
5
解决办法
10万
查看次数

Rails 3.创建生产数据库

如何在Rails 3中创建生产数据库并加载架构?

我尝试了以下方法......

一世.

rake db:create Rails.env='production' && rake db:schema:load Rails.env='production'
Run Code Online (Sandbox Code Playgroud)

II.

# config/environment.rb
# Set the rails environment
Rails.env='production'
rake db:create && rake db:schema:load
Run Code Online (Sandbox Code Playgroud)

......但它们都不起作用.

谢谢.

Debian GNU/Linux 5.0.6;

Rails 3.0.0;

Sqlite3 3.7.2.

ruby ruby-on-rails database-schema

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

17
推荐指数
2
解决办法
4963
查看次数

Capybara&Cucumber | 获取cookie

我正在尝试在Cucumber步骤中获取cookie值:

步骤定义

When /^I log in$/ do
  # code to log in
end

Then /^cookies should be set$/ do
  cookies[:author].should_not be_nil
end
Run Code Online (Sandbox Code Playgroud)

调节器

class SessionsController < ApplicationController
  def create
    cookies[:author] = 'me'
    redirect_to authors_path
  end
end
Run Code Online (Sandbox Code Playgroud)

但它不起作用:

结果

expected: not nil
     got: nil
Run Code Online (Sandbox Code Playgroud)

有趣的是,在RSpec示例中,所有工作都很好:

控制器规格

require 'spec_helper'

describe SessionsController do
  describe 'create' do
    it 'sets cookies' do
      post :create
      cookies[:author].should_not be_nil
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

如何使用Capybara在Cucumber步骤中获取cookie值?

谢谢.

Debian GNU/Linux 6.0.4;

Ruby 1.9.3;

Ruby on Rails 3.2.1;

黄瓜1.1.4;

Cucumber-Rails 1.2.1;

Capybara 1.1.2; …

ruby cucumber capybara

11
推荐指数
2
解决办法
8942
查看次数

BSON | 终端和非终端

通过BSON规范阅读,我遇到了终端非终端条款.例如:

有效的BSON数据由文档非终端表示.

<...>

以下基本类型用作语法其余部分的终端.

在BSON规范的背景下,"终端"和"非终端"是什么意思?

bson

10
推荐指数
1
解决办法
9736
查看次数

Checkinstall无法生成Ruby 1.9.2包

Checkinstall无法生成包含以下错误的Ruby包.

# checkinstall -D --install=no --pakdir=/home/<username>/???????\ ????/

<...>

installing binary commands:   /usr/local/bin
/home/<username>/??????? ????/ruby-1.9.2-p180/lib/fileutils.rb:854:in `utime': No such file or directory - /usr/local/bin/ruby (Errno::ENOENT)
    from /home/<username>/??????? ????/ruby-1.9.2-p180/lib/fileutils.rb:854:in `block in install'
    from /home/<username>/??????? ????/ruby-1.9.2-p180/lib/fileutils.rb:1423:in `block in fu_each_src_dest'
    from /home/<username>/??????? ????/ruby-1.9.2-p180/lib/fileutils.rb:1437:in `fu_each_src_dest0'
    from /home/<username>/??????? ????/ruby-1.9.2-p180/lib/fileutils.rb:1421:in `fu_each_src_dest'
    from /home/<username>/??????? ????/ruby-1.9.2-p180/lib/fileutils.rb:850:in `install'
    from ./tool/rbinstall.rb:154:in `install'
    from ./tool/rbinstall.rb:307:in `block in '
    from ./tool/rbinstall.rb:542:in `call'
    from ./tool/rbinstall.rb:542:in `block (2 levels) in '
    from ./tool/rbinstall.rb:539:in `each'
    from ./tool/rbinstall.rb:539:in `block in '
    from ./tool/rbinstall.rb:535:in `each'
    from ./tool/rbinstall.rb:535:in `'
make: …

ruby checkinstall

8
推荐指数
1
解决办法
2053
查看次数

Ruby on Rails.Unicode路由

是否可以在Rails中将Unicode字符串设置为路径的一部分?

我尝试以下方法:

  
# app/controllers/magazines_controller.rb

class MagazinesController < ApplicationController
  def index                                     
  end                                                                           
end
  
  
# encoding: utf-8
# config/routes.rb

PublishingHouse::Application.routes.draw do
  resources :magazines,
    :only => :index,
    :path => :??????? # a Unicode string is set as a segment of the path
end
  
$ rake routes
magazines GET /???????(.:format) {:action=>"index", :controller=>"magazines"}

但是当我走到路径时,我收到路由错误:

$ w3m http://localhost:3000/???????
...

Routing Error

No route matches "/%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB%D1%8B"

这是服务器日志:

$ rails s thin
...

Started GET "/%D0%B6%D1%83%D1%80%D0%BD%D0%B0%D0%BB%D1%8B" for 127.0.0.1 at 2010-09-26 13:35:00 +0400

ActionController::RoutingError (No route matches …

ruby unicode routes ruby-on-rails

7
推荐指数
1
解决办法
1440
查看次数

Ruby on Rails.捆绑.黄瓜.耙子流产了!命令失败,状态为(1)

使用Bundler和Cucumber与Rails 3时遇到问题.

当我运行时,$ rake cucumber我得到以下输出:

bundle exec /usr/local/bin/ruby -I "/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-
0.8.5/lib:lib" "/usr/local/lib/ruby/gems/1.9.1/gems/cucumber-0.8.5/bin/cucumber"  --profile default
(in /home/<username>/practice/rails/blog)
Using the default profile...
UUUU

1 scenario (1 undefined)
4 steps (4 undefined)
0m1.552s

You can implement step definitions for undefined steps with these snippets:

Given /^a post$/ do
  pending # express the regexp above with the code you wish you had
end

Given /^a name was specified$/ do
  pending # express the regexp above with the code you wish you had …

ruby ruby-on-rails cucumber bundler

6
推荐指数
1
解决办法
5450
查看次数

RubyGems的.Rails中的LoadError

每次我启动我的Rails应用程序时,我都会得到具有以下输出的LoadError.

在Rails 2.3.8上:

no such file to load -- sqlite3/sqlite3_native
<internal:lib/rubygems/custom_require>:29:in `require'

在Rails 3.0.0上:

no such file to load -- bundler
<internal:lib/rubygems/custom_require>:29:in `require'

我使用Nginx + Passenger在开发机器上以生产模式运行应用程序.

这个问题的原因是什么?我该如何解决?

谢谢.

Debian GNU/Linux 5.0.6;

Ruby 1.9.2;

Rubygems 1.3.7;

Ruby on Rails 2.3.8,3.0.0;

Nginx 0.8.50;

乘客2.2.15;

sqlite3-ruby 1.3.1;

bundler 1.0.0.rc.6.

更新


我的所有宝石都是由非特权用户在本地目录中安装的/home/<usernam>/.gem.如果它有帮助,这是gem env输出:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.7
  - RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [i686-linux]
  - INSTALLATION DIRECTORY: /home/<username>/.gem
  - RUBY EXECUTABLE: /usr/local/bin/ruby
  - EXECUTABLE DIRECTORY: …

ruby rubygems ruby-on-rails

5
推荐指数
1
解决办法
1万
查看次数

RSpec的.如何为管道或重定向输出着色?

在2.0之前的RSpec版本中,我可以将颜色输出管道输出更少或将其重定向到文件.为了做到这一点,我只需要将RSPEC_COLOR环境变量设置为true.但是,在框架的新主要版本中,此变量已停止以定义输出类型(颜色或monchrome).有没有办法在RSpec 2.0及更高版本中管道或重定向颜色?

谢谢.

Debian GNU/Linux 5.0.7;

Ruby 1.9.2;

RSpec 2.4.0.

更新


我自己找到了答案.

应该使用tty配置选项来实现效果.

这是一个例子:

# spec/spec_helper.rb

RSpec.configure do |config|
  config.tty = true
end
Run Code Online (Sandbox Code Playgroud)

ruby bdd rspec

5
推荐指数
1
解决办法
1558
查看次数

Ruby on Rails.自定义验证器方法中的自定义消息

我希望能够在模型验证器方法中设置自定义消息,以通知用户不正确的输入数据.

首先,我设置了一个自定义验证器类,我按照rails的文档中的建议重新定义了该validate_each方法:


# app/models/user.rb

# a custom validator class
class IsNotReservedValidator < ActiveModel::EachValidator
  RESERVED = [
    'admin',
    'superuser'
  ]

  def validate_each(record, attribute, value)
    if RESERVED.include? value
      record.errors[attribute] <<
        # options[:message] assigns a custom notification
        options[:message] || 'unfortunately, the name is reserved'
    end
  end
end

其次,我尝试validates通过两种不同的方式将自定义消息传递给方法:


# a user model
class User < ActiveRecord::Base
  include ActiveModel::Validations

  ERRORS = []

  begin
    validates :name,
      :is_not_reserved => true,
      # 1st try to set a custom message
      :options         => …
Run Code Online (Sandbox Code Playgroud)

ruby validation ruby-on-rails

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