Tag: ruby

未定义的方法`source_index'为Gem:Module(NoMethodError)

我正在运行一个Rails 2.3.5应用程序,并运行脚本/服务器时,我显示以下内容: ./script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module (NoMethodError) from ./script/../config/boot.rb:60:in `load_initializer' from ./script/../config/boot.rb:44:in `run' from ./script/../config/boot.rb:17:in `boot!' from ./script/../config/boot.rb:123 from script/server:2:in `require' from script/server:2 如果我在boot.rb(Rails :: GemDependency.add_frozen_gem_path)中注释掉第60行并运行脚本/服务器,我得到这个: => Booting WEBrick => Rails 2.3.5 application starting on http://0.0.0.0:3000 ./script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module (NoMethodError) from ./script/../config/../vendor/rails/railties/lib/initializer.rb:298:in `add_gem_load_paths' from ./script/../config/../vendor/rails/railties/lib/initializer.rb:132:in `process' from ./script/../config/../vendor/rails/railties/lib/initializer.rb:113:in […]

所有Rubytesting提升:nil:NilClass的未定义方法`authenticate'

我的大多数testing都提出以下,我不明白为什么。 所有的方法调用都会引发“validation”错误。 我已经检查了代码是否有一个称为“authentication”的方法,但没有这样的方法。 1) Admin::CommentsController handling GET to index is successful Failure/Error: get :index undefined method `authenticate!' for nil:NilClass # ./spec/controllers/admin/comments_controller_spec.rb:9:in `block (3 levels) in <top (required)>' 124) PostsController handling GET for a single post should render show template Failure/Error: get :show, :year => '2008', :month => '01', :day => '01', :slug => 'a-post' undefined […]

Ubuntu的noob rails安装在zlib上失败

我刚刚移动到Ubuntu 8.10作为我的开发盒; 这是我作为一个日常使用的操作系统的第一次严重的入侵Linux,我很难让Rails去。 我已经遵循了许多教程,似乎都工作正常,但是当我尝试使用任何gem install或gem更新时,我得到一个如下所示的错误: /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load — zlib (LoadError) from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:1 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/commands/update_command.rb:5 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:167:in `load_and_instantiate' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:88:in `[]' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:144:in `find_command' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:131:in `process_args' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/command_manager.rb:102:in `run' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/gem_runner.rb:58:in `run' from /usr/local/bin/gem:21 我有(如教程中推荐的)安装了zlib,zlib1g和zlib1g-dev。 […]

如何在ruby中做一个安全的连接path名?

我的Rails开发环境是基于Windows的,我的生产环境是基于Linux的。 VirtualHost可能会被使用。 假定一个文件名需要在File.open('/tmp/abc.txt', 'r')的/public文件夹中被引用。 但在Windows中,应该是C:\tmp\abc.txt 。 我如何做一个正确的path连接来处理这两个不同的环境? prefix_tmp_path = '/tmp/' filename = "/#{rand(10)}.txt" fullname = prefix_tmp_path + filename # /tmp//1.txt <- but I don't want a double // 当prefix_tmp_path = "C:\tmp\"我得到C:\tmp\/1.txt 处理这两种情况的正确方法是什么?

Ruby on Rails:如何呈现一个string为HTML?

我有 @str = "<b>Hi</b>" 并在我的观点: <%= @str %> 什么将显示在页面上: <b>Hi</b>什么时候我真正想要的是嗨 。 什么是ruby的方式来解释一个string为HTML标记? 编辑 :在哪里的情况 @str = "<span class=\"classname\">hello</span>" 如果在我看来我是这样做的 <%raw @str %> HTML源代码是<span class=\"classname\">hello</span >,我真正想要的是<span class="classname">hello</span> (没有用双引号括起来的反斜杠) 。 什么是“避免”这些双引号的最好方法?

将时间戳添加到现有的表

我需要添加时间戳(created_at updated_at)到一个现有的表。 我试过下面的代码,但没有奏效。 我也试过了我在网上find的其他解决scheme,但是他们也不pipe用。 class AddTimestampsToUser < ActiveRecord::Migration def change_table add_timestamps(:users) end end 我该怎么做?

等效的.try()散列,以避免“未定义的方法”错误的零?

在Rails中,如果值不存在以避免错误,我们可以执行以下操作: @myvar = @comment.try(:body) 什么是当我深入到一个散列,不想得到一个错误的等价物? @myvar = session[:comments][@comment.id]["temp_value"] # [:comments] may or may not exist here 在上述情况下, session[:comments]try[@comment.id]不起作用。 什么会?

如何在Ruby中将string或整数转换为二进制文件?

你如何创build整数0..9和math运算符+ – * / in到二进制string。 例如: 0 = 0000, 1 = 0001, … 9 = 1001 有没有办法使用Ruby 1.8.6而不使用库?

从string中删除子string

我只是想知道是否有任何方法从另一个string中删除string? 像这样的东西: class String def remove(s) self[s.length, self.length – s.length] end end

Rails 4 – Gem :: LoadError:为数据库适配器指定'mysql2',但没有加载gem

在我的gemfile中我有: gem 'mysql2' 我的database.yml如下所示: default: &default adapter: mysql2 database: <%= ENV['db_name'] %> username: <%= ENV['db_user'] %> password: <%= ENV['db_pass'] %> host: <%= ENV['db_host'] %> pool: 32 socket: <%= ENV['socket'] %> development: <<: *default production: <<: *default 我已经运行bundle update和bundle install ,我的Gemfile.lock显示mysql2。 但是当我运行rake db:migrate我在计算机和登台服务器上都得到了这个: myproject.com(master)$ rake db:migrate WARNING: Use strings for Figaro configuration. 10000012508 was converted to […]