小编mat*_*att的帖子

Thin&Sinatra没有接收端口

我在使用Thin和Sinatra设置我的应用程序时遇到了问题.我创建了一个包含以下设置的development-config.ru文件:

# This is a rack configuration file to fire up the Sinatra application.
# This allows better control and configuration as we are using the modular
# approach here for controlling our application.
#
# Extend the Ruby load path with the root of the API and the lib folder
# so that we can automatically include all our own custom classes. This makes
# the requiring of files a bit cleaner and easier to maintain.
# This is …
Run Code Online (Sandbox Code Playgroud)

ruby rack thin sinatra

3
推荐指数
1
解决办法
1877
查看次数

bcrypt-ruby不会与bundler一起安装,但可以在gem install中正常工作

我刚刚开始遇到捆绑软件问题 - 在进行捆绑安装或sudo捆绑安装时,bcrypt-ruby将无法安装,并退出时出现以下错误:

Installing bcrypt-ruby (2.1.4) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb 

Gem files will remain installed in /home/deploy/vendor/bundle/ruby/1.8/gems/bcrypt-ruby-2.1.4 for inspection.
Results logged to /home/deploy/vendor/bundle/ruby/1.8/gems/bcrypt-ruby-2.1.4/ext/mri/gem_make.out
An error occured while installing bcrypt-ruby (2.1.4), and Bundler cannot continue.
Make sure that `gem install bcrypt-ruby -v '2.1.4'` succeeds before bundling.
Run Code Online (Sandbox Code Playgroud)

但是,gem install bcrypt-ruby -v '2.1.4'运行得很好(事实上已经在这个盒子上运行)./usr/bin/ruby1.8 extconf.rb手动运行工作正常,生成的Makefile也可以运行make.

我在Ubuntu 10.04.1 LTS上使用Ruby 1.8.7和bundler 1.0.21.其他宝石似乎通过捆绑工具正常工作.虽然这可能很明显,但我已经确认安装了ruby-dev,gcc等软件包.我尝试使用带有bundler的--deployment选项,没有不同的行为.我最近唯一想到的改变就是几天前我做了一个捆绑更新,所以捆绑包得到了一个小版本更改(1.0.10 - > 1.0.21)并且bcrypt似乎得到了一个主要的版本更改(2.1 .4 - > 3.0.1).

任何帮助表示赞赏!

ruby rubygems bcrypt bundler

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

DataMapper - 单表继承

有人可以向我解释这里发生了什么吗?

这是一个我放在一起展示你们最新情况的例子:

class Person
  include DataMapper::Resource
  property :id, Serial
  property :type, Discriminator
  property :name, String
  property :age, Integer
end

class Male < Person
end

class Father < Male
  property :job, String
end

class Son < Male
end

class Female < Person
end

class Mother < Female
  property :favorite_song, String
end

class Daughter < Female
end

DataMapper.auto_upgrade!
Run Code Online (Sandbox Code Playgroud)

如果我打电话给Person.all我:

Person.all
=> [#<Son @id=1 @type=Son @name="Mike" @age=23 @status=nil>, 
#<Son @id=2 @type=Son @name="Carlos" @age=12 @status=nil>, 
#<Father @id=3 @type=Father @name="Robert" @age=55 @job=<not loaded>>, …
Run Code Online (Sandbox Code Playgroud)

ruby single-table-inheritance sinatra ruby-datamapper

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

bundle命令的Gemfile错误

我是应用程序的合作者,我克隆了,并且在我的协作者的计算机上一切都运行得很好.但是,当我在我的Heroku应用程序的根目录中键入bundle exec或bundle install时,出现以下错误:

/Users/jacob/furious-ocean-6331/Gemfile:3:in `evaluate': undefined method `ruby' for # <Bundler::Dsl:0x007fcda31048c0> (NoMethodError)
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/dsl.rb:7:in `instance_eval'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/gems/bundler1.1.4/lib/bundler/dsl.rb:7:in `evaluate'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/definition.rb:18:in `build'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler.rb:135:in `definition'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/gems/bundler1.1.4/lib/bundler/cli.rb:220:in `install'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/gems/bundler1.1.4/lib/bundler/vendor/thor/task.rb:22:in `run'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/vendor/thor.rb:263:in `dispatch'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/lib/bundler/vendor/thor/base.rb:386:in `start'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/gems/bundler-1.1.4/bin/bundle:13:in `<top (required)>'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/bin/bundle:19:in `load'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/bin/bundle:19:in `<main>'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
       /Users/jacob/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'
There was an error in your Gemfile, and Bundler cannot continue.
Run Code Online (Sandbox Code Playgroud)

这是Gemfile:

source 'https://rubygems.org'

ruby '1.9.3'
gem 'rails', '3.2.2'

# Bundle edge Rails instead: 
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'nokogiri'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem "json", …
Run Code Online (Sandbox Code Playgroud)

bundle heroku nomethoderror gemfile

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

Ruby 从 json 文件中放入键而不是值

我的 ruby​​ 和 json 有问题。\n我有一个 json 文件,其中包含从互联网上抓取的信息。对于以下问题,我将使用硬编码文件,其语法如下:

\n\n
[{\n  "day": "20120827_234558",\n  "entries": [\n    {\n      "rank": "3",\n      "club": "SuS Schalke 1896 e.V.",\n      "votes": "126"\n    },\n    {\n      "rank": "4",\n      "club": "TuS Hamborn-Neum\xc3\xbchl 07 e.V.",\n      "votes": "120"\n    }\n]\n},{\n  "day": "20120827_234700",\n  "entries": [\n    {\n      "rank": "1",\n      "club": "TLV Germania 1901 Essen-\xc3\x9cberruhr",\n      "votes": "210"\n    },\n    {\n      "rank": "2",\n      "club": "Rumelner TV",\n      "votes": "141"\n    }\n]\n}]\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后我编写了一个 ruby​​ 脚本,它从文件中加载 json 并将其放入哈希中,\n从互联网上获取一些信息(在本例中也是硬编码的),将这些新信息添加到哈希中,将哈希转换为 json并将其再次存储在文件中。

\n\n
require \'rubygems\'\nrequire \'open-uri\'\nrequire \'json\'\n\nfname = \'ranking.json\'\n\njson = JSON.load(File.open(fname))\n\njson.each do |ranking|\n  puts \'entry:\'\n  puts …
Run Code Online (Sandbox Code Playgroud)

ruby json

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

Haml 的 Rails 助手

我有一些 HAML 代码在 10 个视图中重复出现,并希望将其放入某种帮助程序中。在这里进行搜索产生了一些有趣的结果,但最终没有答案,所以:

application_helper.rb我有这个:

def pagination_helper(object)
  haml_tag :div, :class => 'apple_pagination page_info' do
    page_entries_info @book_formats
    paginate @book_formats
  end
end
Run Code Online (Sandbox Code Playgroud)

在视图模板中,我有这个:

- pagination_helper(@book_formats)
Run Code Online (Sandbox Code Playgroud)

如果我尝试调用它=以输出某些内容,则会出现错误。

以上不会给我一个错误,但它也不会调用这些方法。我得到空的div。

最终我想重复的代码是这样的:

.apple_pagination.page_info
  = page_entries_info @book_formats
  = paginate @book_formats
Run Code Online (Sandbox Code Playgroud)

代码将是相同的,除了object会发生变化并且我从视图模板发送它。例如@book_formats将更改为@dvds等。

haml ruby-on-rails-3.1

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

问号在ruby中的函数定义中意味着什么?

我有这样的功能 -

函数名称为seld.is_dl,它接受路径参数.我的问题是这个?函数定义中的符号表示什么.

def self.is_dl?(path)

  path = File.basename(path)

  if path =~ /setup.exe/i

    return false

  else

    return true

  end

end
Run Code Online (Sandbox Code Playgroud)

我是java开发人员,我看过"?" 在主要是If-ELSE块的情况下,这就是为什么我无法确定这是什么意思?

ruby

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

Rails使用系统版本的ruby而不是Chruby set default

我使用Chruby ruby​​版本控件设置我的ruby默认值,但是当我尝试使用我的系统版本时,它会使用我的系统版本.我该如何解决?

~/workspace ??? ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
~/workspace ??? ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
~/workspace ??? rails new gitsee   
    Rails 5 requires Ruby 2.2.2 or newer.

    You're running
      ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

    Please upgrade to Ruby 2.2.2 or newer to continue.
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails chruby

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

socket.io没有在heroku上工作

每当我尝试require("socket.io");在heroku 上使用它时都会失败并显示消息"找不到模块socket.io".

我认为这是我的设置问题,因为我的本地node.js服务器运行正常.

我需要改变什么?

heroku node.js

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

C忽略"if"指令

我最近做的一个程序有问题.基本上,这是John Conway的生活游戏的简单版本,但它不能正常工作.问题出在代码中,它读取单元格及其邻居的状态并决定该单元格的未来状态.这是代码的一部分(它有点长):

#include<stdio.h>
#include<conio.h>

//Game grid size
#define SIZE 15

//Cell state (wall is a special state. It protects the other cells from garbage data of the heap memory)
enum cellState {dead,alive,wall};

//Function prototypes
int** load(int**);
void process(int**);

int main(){

    //Game grid (2-D matrix) and its memory allocation
    int** grid;

    grid=(int**)calloc(SIZE+2,sizeof(int*));
    for(int cont=0;cont<SIZE+2;cont++){
        *(grid+cont)=(int*)calloc(SIZE+2,sizeof(int));
    }

    load(grid);
    getch();
    process(grid);
    getch();
}

//Grid loading function
int** load(int** grid){

    int type;
    srand(12345);
    for(int cont=0;cont<SIZE+2;cont++){
        for(int cont2=0;cont2<SIZE+2;cont2++){
            if(cont==0||cont==TAMANO+1||cont2==0||cont2==TAMANO+1){
                *(*(grid+cont)+cont2)=wall;
            }
            else{
                //Cell type decision …
Run Code Online (Sandbox Code Playgroud)

c

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