小编Dav*_*acs的帖子

gem install pg在OSX Lion上不起作用

这个问题有各种各样的变化,但是它们似乎都没有解决我问题的答案.

我正在运行OSX Lion(10.7.3).安装了最新的XCode.

我使用postgresapp.com的Postgres.app包安装了Postgres.

但是当我尝试安装pg gem时,我遇到了失败:

$ gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
Using config values from /Applications/Postgres.app/Contents/MacOS/bin/pg_config
checking for libpq-fe.h... *** 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
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib …
Run Code Online (Sandbox Code Playgroud)

ruby postgresql rubygems pg osx-lion

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

使用log4j进行条件记录

我工作的Web应用程序偶尔会为某些用户开发数据完整性问题.我想打开跟踪级别日志记录,但由于我们每秒处理100个请求跟踪日志记录,因此每个请求都是不可能的.

有没有办法让log4j能够有条件地记录?换句话说,我希望只有在特定用户发出请求时才能获取跟踪日志.由于我事先不知道哪些用户会受到影响,我不能简单地暂时硬编码用户名.

编辑:

我想我需要更清楚一些.我可以轻松地为日志语句添加条件.例如

Logger logger = Logger.getLogger("foo");
String usernameFilter = "piglet";
String username = request.getParameter("username");
logger.setLevel(usernameFilter.equals(username) ? Level.TRACE : Level.INFO);
if (logger.isTraceEnabled()) {
   logger.trace("blah blah blah");
}
Run Code Online (Sandbox Code Playgroud)

困难在于动态地改变设置日志级别的条件.换句话说,在上面的示例中,我如何设置usernameFilter的值,而不是硬编码.

java log4j

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

安装RMagick gem - 找不到MagickWand.h

我在OSX 10.6.8上安装rmagick gem,使用gem install rmagick,我收到以下错误

    Can't install RMagick 2.13.1. Can't find MagickWand.h.
*** 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
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/disaacs/.rvm/rubies/ruby-1.9.3-p125/bin/ruby


Gem files will remain installed in /Users/disaacs/.rvm/gems/ruby-1.9.3-p125/gems/rmagick-2.13.1 for inspection.
Results logged to /Users/disaacs/.rvm/gems/ruby-1.9.3-p125/gems/rmagick-2.13.1/ext/RMagick/gem_make.out
Run Code Online (Sandbox Code Playgroud)

查看我看到的mkmf.log文件

have_header: checking for wand/MagickWand.h... -------------------- no

"/usr/bin/gcc-4.2 -E …
Run Code Online (Sandbox Code Playgroud)

ruby rmagick osx-snow-leopard

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

这个MiniTest :: Unit :: TestCase警告是什么意思?

我的测试运行没有问题,突然出现以下警告:

MiniTest::Unit::TestCase is now Minitest::Test
Run Code Online (Sandbox Code Playgroud)

这在以下库中报告:

ruby-1.9.3-p392/lib/ruby/1.9.1/test/unit/testcase.rb:8:in `<module:Unit>'
gems/activesupport-3.2.12/lib/active_support/test_case.rb:12:in `<module:ActiveSupport>'
gems/activesupport-3.2.12/lib/active_support/descendants_tracker.rb:34:in `inherited'
Run Code Online (Sandbox Code Playgroud)

我不知道是什么促使出现这些警告.有人知道我能做些什么来消除警告吗?

即使有警告,测试仍然可以正常运行.

我的Rails环境是3.2.12,在OSX 10.8.4上运行.

谢谢!

ruby-on-rails minitest

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

无法卸载捆绑程序 1.17.3

我当前的捆绑程序版本似乎是 1.17.3。我最近的工作实际上需要 1.17.2,但我无法卸载 1.17.3。

如果我运行gem uninstall bundler命令退出,没有输出。该命令gem info bundler始终显示版本 1.17.3。

$ gem uninstall bundler
$ gem info bundler

*** LOCAL GEMS ***
... yada yada yada ...
bundler (1.17.3)
    Installed at (default): /Users/disaacs/.rvm/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0
Run Code Online (Sandbox Code Playgroud)

如果我安装了我需要的 bundler 版本,我会安装两个版本,但 1.17.3 版本默认运行。

$ gem install bundler -v 1.17.2
Fetching bundler-1.17.2.gem
Successfully installed bundler-1.17.2
Parsing documentation for bundler-1.17.2
Installing ri documentation for bundler-1.17.2
Done installing documentation for bundler after 3 seconds
1 gem installed
$ gem info bundler

*** LOCAL GEMS …
Run Code Online (Sandbox Code Playgroud)

ruby rubygems bundler rvm

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

"HTTPI尝试使用Savon SOAP库来使用httpi适配器"错误

我正在使用Savon为SOAP服务编写Ruby接口.它似乎正在工作,但我在命令行上出现了几个DEBUG消息

D, [2011-02-15T16:33:32.664620 #4140] DEBUG -- : HTTPI tried to use the httpclient adapter, but was unable to find the library in the LOAD_PATH. Falling back using the net_http adapter now.

D, [2011-02-15T16:33:32.820863 #4140] DEBUG -- : HTTPI executes HTTP POST using the net_http adapter

D, [2011-02-15T16:33:32.664620 #4140] DEBUG -- : HTTPI tried to use the httpclient adapter, but was unable to find the library in the LOAD_PATH. Falling back using the net_http adapter now.

D, [2011-02-15T16:33:32.820863 #4140] DEBUG -- …

ruby soap savon httpi

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

保存模型时,关联"无效"

我有一个俱乐部模型和一个会员模型,它们通过会员模型关联.换一种说法

class Club < ActiveRecord::Base
  has_many :members, :through => :memberships
end

class Member < ActiveRecord::Base
  has_many :clubs, :through => :memberships
end
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试创建新成员并将其添加到俱乐部时,我收到一条错误消息,说俱乐部无效.

> club = Club.find(1)
> member = Member.new(:name => 'Member Name')
> member.clubs << club
> member.save
Run Code Online (Sandbox Code Playgroud)

member.save陈述将返回false.看一下member.errors.messages,我发现

> member.errors.messages
@messages={:clubs=>["is invalid"]}
Run Code Online (Sandbox Code Playgroud)

真奇怪的是,我的开发环境(使用sqlite3)不会发生这种情况,但仅限于使用mySQL进行的EngineYard部署.

ruby-on-rails

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

在Sendgrid X-SMTPAPI标头中,新行解析为= 0A

我使用Sendgrid将邮件发送到邮件列表,使用X-SMTPAPI标头指定多个收件人.从Sendgrid文档 "必须包装标题以保持行长度低于72".

我正在使用ActionMailer发送电子邮件,并使用该headers方法设置X-SMTPAPI标头.为了保持少于72个字符的行,我尝试用逗号+换行符+空格替换每个逗号.例如,

headers["X-SMTPAPI"] = {
        :to => ['user1@example.com','user2@example.com','user3@example.com','user4@example.com','user5@example.com','user6@example.com']
}.to_json.gsub(',',",\n ")
Run Code Online (Sandbox Code Playgroud)

而不是在我的标题中获取换行符,我得到以下(从日志文件)

X-SMTPAPI: {"to":["user1@example.com",=0A "user2@example.com",=0A "user3@example.com",=0A "user4@example.com",=0A "user5@example.com",=0A "user6@example.com"]}
Run Code Online (Sandbox Code Playgroud)

请注意,\n字符正在替换为=0A.Sendgrid服务器将此序列拒绝为无效.

我有什么想法可以将正确的换行符添加到标题中?

编辑:我尝试添加"puts headers"以查看标题中设置的内容.然后就是我发现的

Date: Sat, 13 Apr 2013 18:21:36 -0400
Message-ID: <5169da701cd26_5343fe1776afc50749b4@saunders.mail>
Mime-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
X-SMTPAPI: {"to":["user1@example.com",=0A "user2@example.com",=0A
 "user3@example.com",=0A "user4@example.com",=0A "user5@example.com",=0A
 "user6@example.com"]}
Run Code Online (Sandbox Code Playgroud)

请注意,我添加的换行符仍然显示为"= 0A".但有些东西似乎在增加自己的包装.这种包装是自动的,并且足以使我的标题行长度不超过要求吗?

ruby ruby-on-rails sendgrid

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

在Sinatra中获取唯一的会话ID

我有一个使用Sinatra构建的简单Web应用程序,并启用了会话。

如果我理解正确,则会话数据存储在编码的cookie中。随着会话数据的更改,cookie的值也将更改。

我需要一个唯一的会话标识符,在整个会话过程中保持不变。是否有这样的标识符。还是我必须创建自己的独特价值并将其自己存储在会话中?

谢谢!

编辑:在下面的评论中,我想到了一个有用的比较。如果我有一个Java servlet,我将使用JSESSIONID作为唯一标识符。我需要一个等效于JSESSIONID的Sinatra。

ruby sinatra

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

使用STI model_name解决方法的弃用警告

在我的单表继承模型中,我重写了inherited基本模型中的方法,以便所有后代模型都可以被基本模型的名称识别.以下代码用于为所有继承的类添加对model_name方法的覆盖.

  def self.inherited(child)
    child.instance_eval do
      def model_name
        BaesModelDefinition.model_name
      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

我注意到这是在Rails 3.2.3中产生弃用警告:

DEPRECATION WARNING: It looks like something (probably a gem/plugin) is overriding 
the ActiveRecord::Base.inherited method. It is important that this hook executes so 
that your models are set up correctly. A workaround has been added to stop this 
causing an error in 3.2, but future versions will simply not work if the hook is
overridden.
Run Code Online (Sandbox Code Playgroud)

我可以使用另一种方法来修复model_name问题吗?

ruby-on-rails sti ruby-on-rails-3

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