小编Зел*_*ный的帖子

Gem :: Ext :: BuildError:错误:无法构建gem原生扩展. - CentOS 6.5

我试图让Ruby版本2.0.0-p353在CentOS 6.5上的Nginx 1.4.7上运行.一切都按预期安装,但当我到达运行点时,bundle install我收到以下错误:

Gem :: Ext :: BuildError:错误:无法构建gem原生扩展.

/usr/local/rvm/rubies/ruby-2.0.0-p353/bin/ruby extconf.rb 
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog …
Run Code Online (Sandbox Code Playgroud)

ruby postgresql centos ruby-on-rails

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

Capistrano 3,使用上传!在lib/capistrano/tasks中的任务中

我正在使用Capistrano 3,我想创建自己的任务.所以我在lib/capistrano/tasks中创建了一个文件my_new_thing.rake,当我运行cap -T时我可以看到任务.但是......有些方法不可用.当我尝试使用上传!我明白了

cap aborted!
NoMethodError: undefined method `upload!' for main:Object
Run Code Online (Sandbox Code Playgroud)

但是,如果我将相同的任务移动到config/deploy.rb然后上传!方法可用.

发生什么了?如何创建新的Capistrano任务将它们放在单独的文件中并让它们工作?

ruby ruby-on-rails capistrano3

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

rails,docker - cron任务不运行

我的crontasks来自docker schedule.rb容器不起作用,但 crontab -l结果已包含以下行:

# Begin Whenever generated tasks for: /app/config/schedule.rb
45 19 * * * /bin/bash -l -c 'bundle exec rake stats:cleanup'
45 19 * * * /bin/bash -l -c 'bundle exec rake stats:count'
0 5 * * * /bin/bash -l -c 'bundle exec rake stats:history'
# End Whenever generated tasks for: /app/config/schedule.rb
Run Code Online (Sandbox Code Playgroud)

我可以在容器中手动运行此命令,它可以工作.似乎cron没有开始.

Dockerfile:

FROM ruby:2.4.0-slim
RUN apt-get update
RUN apt-get install -qq -y --no-install-recommends build-essential libpq-dev cron postgresql-client
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime
ENV LANG C.UTF-8 …
Run Code Online (Sandbox Code Playgroud)

cron ruby-on-rails whenever docker

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

无法打开到 :80 HTTParty gem 的 TCP 连接

因此,在我的 Coursera 课程中,我需要构建这个相当简单的应用程序,以从外部 api 获取和显示数组。我正在使用 ruby​​ on rails 框架。(我使用的是 Windows 10)

控制器 -

class CoursesController < ApplicationController
  def index
    @search_term = params[:looking_for] || 'jhu'
    @courses = Coursera.for(@search_term)
  end
end
Run Code Online (Sandbox Code Playgroud)

模型

class Coursera 
    include HTTParty
    default_options.update(verify: false) # Turn off SSL verification
    base_uri 'https://api.coursera.org/api/courses.v1'
    default_params fields: "photoUrl,description",q: "search"
    format :json

    def self.for term
        get("",query: {query: term}) ["elements"]
    end
end
Run Code Online (Sandbox Code Playgroud)

该视图无关紧要,因为它可以正常工作。但在我的其他应用程序中,我收到此错误 -

Errno::ECONNREFUSED: Failed to open TCP connection to :80 (Connection refused - connect(2) for nil port 80)
Run Code Online (Sandbox Code Playgroud)

这是我遇到问题的另一个应用程序 -

控制器 - …

ruby ruby-on-rails httparty

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

如何在go中测试http调用

我有以下代码:

// HTTPPost to post json messages to the specified url
func HTTPPost(message interface{}, url string) (*http.Response, error) {
    jsonValue, err := json.Marshal(message)
    if err != nil {
        logger.Error("Cannot Convert to JSON: ", err)
        return nil, err
    }
    logger.Info("Calling http post with url: ", url)
    resp, err := getClient().Post(url, "application/json", bytes.NewBuffer(jsonValue))
    if err != nil {
        logger.Error("Cannot post to the url: ", url, err)
        return nil, err
    }
    err = IsErrorResp(resp, url)
    return resp, err
}
Run Code Online (Sandbox Code Playgroud)

我想为此编写测试,但我不确定如何使用 httptest 包。

unit-testing go

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

如何仅根据日和月获取用户的生日

我想要一份今天生日和即将到来的生日(明天)的会员名单。

In users.controller.rb
def birthday
   @birthday_users = User.all.order("created_at DESC").where(:birthday => Date.today)
end

def upcoming_birthday
   @upcoming_birthday_user = User.all.order("created_at DESC").where(:birthday => 1.days.from_now )
end
Run Code Online (Sandbox Code Playgroud)

仅当日、月、年与今天相同时,这些代码才有效。

例子:

用户1的生日=2018年10月3日(显示在生日列表中)

用户2的生日=2000年10月3日(未显示在生日列表中)

postgresql ruby-on-rails date

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

在rails中添加add_foreign_key和add_reference

rails中"add_foreign_key""add_reference"方法有什么区别?

根据rails官方指南,我所理解的是它们都用于在两个表之间创建外键约束.

ruby ruby-on-rails

4
推荐指数
2
解决办法
932
查看次数

模块类 &lt;&lt; 自常量

有我的L常数吗?

module M
  class Z
    class << self
      L = "foo"
    end
  end
end

=> M::Z::L
=> NameError: uninitialized constant M::Z::L
=> M::Z.constants
=> []

module B
  class N
    X = "bar"
  end
end

=> B::N::X
=> "bar"
=> B::N.constants
=> [:X]
Run Code Online (Sandbox Code Playgroud)

我读了这个,但我不明白。

ruby module constants self

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

&lt;class:Numeric&gt;': 堆栈级别太深 (SystemStackError)

我正在尝试 rails 教程,但 rails 服务器无法正常工作http://guides.rubyonrails.org/getting_started.html

$ rvm install ruby-2.4.1
$ rvm use 2.4.1 --default
$ gem install bundler
$ bundle install
Using rake 12.0.0
Using i18n 0.8.1
$ rm -rf vendor/
$ bundle install
$ ./bin/rails server
=> Booting WEBrick
=> Rails 4.2.6 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
/Users/cchilders/tutorials/ruby/rails_official_tutorial/my-code/vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.6/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Fixnum is deprecated
/Users/cchilders/tutorials/ruby/rails_official_tutorial/my-code/vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.6/lib/active_support/core_ext/numeric/conversions.rb:121: warning: constant ::Bignum is deprecated
Exiting
/Users/cchilders/tutorials/ruby/rails_official_tutorial/my-code/vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.6/lib/active_support/core_ext/numeric/conversions.rb:125:in `block (2 …
Run Code Online (Sandbox Code Playgroud)

ruby macos ruby-on-rails

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

紧急服务[:: 1]:46738:运行时错误:无效的内存地址或nil指针取消引用

有人可以解释发生了什么吗?我可能会缺少一些东西吗?我是新手。我正在制作一个简单的CRUD应用程序,它可以正常编译,但是当我启动服务器时,它给了我一个运行时错误。

2017/10/08 11:11:59 http: multiple response.WriteHeader calls
2017/10/08 11:11:59 http: panic serving [::1]:46828: runtime error: invalid memory address or nil pointer dereference
goroutine 19 [running]:
net/http.(*conn).serve.func1(0xc42008ce60)
    /home/vikram/go/src/net/http/server.go:1697 +0xd0
panic(0x740160, 0x97cc10)
    /home/vikram/go/src/runtime/panic.go:491 +0x283
html/template.(*Template).escape(0x0, 0x0, 0x0)
    /home/vikram/go/src/html/template/template.go:95 +0x38
html/template.(*Template).Execute(0x0, 0x94d920, 0xc420186000, 0x719e00, 0x9ab500, 0xc4201820c0, 0x0)
    /home/vikram/go/src/html/template/template.go:119 +0x2f
main.indexHandler(0x9519e0, 0xc420186000, 0xc420160100)
    /home/vikram/Projects/golang/src/github.com/vikramdurai/blog-app-go/main.go:188 +0x185
net/http.HandlerFunc.ServeHTTP(0x7b8da8, 0x9519e0, 0xc420186000, 0xc420160100)
    /home/vikram/go/src/net/http/server.go:1918 +0x44
net/http.(*ServeMux).ServeHTTP(0x98ad20, 0x9519e0, 0xc420186000, 0xc420160100)
    /home/vikram/go/src/net/http/server.go:2254 +0x130
net/http.serverHandler.ServeHTTP(0xc420087110, 0x9519e0, 0xc420186000, 0xc420160100)
    /home/vikram/go/src/net/http/server.go:2619 +0xb4
net/http.(*conn).serve(0xc42008ce60, 0x9520a0, 0xc42007c280)
    /home/vikram/go/src/net/http/server.go:1801 +0x71d
created by net/http.(*Server).Serve
    /home/vikram/go/src/net/http/server.go:2720 +0x288
Run Code Online (Sandbox Code Playgroud)

我的 …

go

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