小编Roh*_*hit的帖子

无法安装pg gem

我尝试使用,gem install pg但它似乎没有用.

gem install pg 给出了这个错误

Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

C:/Ruby/bin/ruby.exe 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. …
Run Code Online (Sandbox Code Playgroud)

ruby installation rubygems ruby-on-rails

209
推荐指数
10
解决办法
13万
查看次数

如何检查字符串中的值是否为IP地址

当我这样做

ip = request.env["REMOTE_ADDR"]
Run Code Online (Sandbox Code Playgroud)

我得到了客户端的IP地址.但是如果我想验证变量中的值是否真的是IP呢?我怎么做?

请帮忙.提前致谢.抱歉,如果重复这个问题,我没有努力找到它......

编辑

那么IPv6 IP呢?

ruby string ip ruby-on-rails ipv6

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

Postgres DB上的整数超出范围

使用Postgres DB的简单rails应用程序,在尝试插入2176968859时出现"整数超出范围"错误.应该可以轻松修复迁移,但我不确定.现在我有......

create_table :targets do |t|
   t.integer :tid
    ...
end
Run Code Online (Sandbox Code Playgroud)

postgresql ruby-on-rails

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

在heroku上实现wicked pdf的问题

我正在使用本指南在heroku上集成wicked_pdf.但不知何故它似乎不起作用.我从heroku获得了日志,它说:

Processing PdfController#get_pdf to pdf (for 115.248.175.50 at 2011-02-15 23:54:44) [GET]
  Parameters: {"format"=>"pdf", "action"=>"get_pdf", "id"=>"1", "controller"=>"pdf"}
***************WICKED***************
Rendering pdf/get_pdf

RuntimeError (PDF could not be generated!
/usr/ruby1.8.7/lib/ruby/1.8/open3.rb:73:in `exec': No such file or directory - /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/bin/wkhtmltopdf-amd64       - -  (Errno::ENOENT)
    from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:73:in `popen3'
    from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:59:in `fork'
    from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:59:in `popen3'
    from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:57:in `fork'
    from /usr/ruby1.8.7/lib/ruby/1.8/open3.rb:57:in `popen3'
    from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/wicked_pdf.rb:22:in `pdf_from_string'
    from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:28:in `make_pdf'
    from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:39:in `make_and_send_pdf'
    from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/vendor/plugins/wicked_pdf/lib/pdf_helper.rb:13:in `render'
    from /app/fa369291-829b-4b61-9efe-b2f0d0a0a42c/home/app/controllers/schedule_controller.rb:33:in `get_pdf'
Run Code Online (Sandbox Code Playgroud)

请帮忙.提前致谢.

编辑:

我在代码中做了一些更改并完成了这个错误,但仍然停留在这里

NoMethodError (undefined method empty? for #<Pathname:0x2b7112392480>)

pdf-generation ruby-on-rails heroku production-environment wicked-pdf

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

Ruby on Rails - 撤消mark_for_destruction

在我的rails应用程序中,子记录得到了marks_for_destruction我想撤消该操作并取消标记它们.有办法吗?

提前致谢.

activerecord ruby-on-rails destroy

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

Setting a :has_many :through association on a belongs_to association Ruby on Rails

I have three models, each having the following associations:

class Model1 < ActiveRecord::Base
  has_many :model2s
  has_many :model3s
end

class Model2 < ActiveRecord::Base
  belongs_to :model1
  has_many :model3s, :through => :model1  # will this work? is there any way around this?
end

class Model3 < ActiveRecord::Base
  belongs_to :model1
  has_many :model2s, :through => :model1  # will this work? is there any way around this?
end
Run Code Online (Sandbox Code Playgroud)

As you can see in the commented text, I have mentioned what I need.

ruby ruby-on-rails associations has-many-through belongs-to

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

知道mongodb中的实际块大小

我试图在我的一个分片集合中找到所有块的大小.

我想知道真正的 大小,而不是作为我知道我可以找到的设置的mongos提示:

use config
db.settings.find({_id : "chunksize"})
Run Code Online (Sandbox Code Playgroud)

我尝试了几种解决方案,但计数操作非常慢,所以这并不容易.你知道解决方案吗?(shell,csharp,python,ruby,bash,我不在乎)

现在我测试了以下内容:

db.getSisterDB("config").chunks.find({ns : "mydb.mycollection"}).forEach(function(chunk) {
     db.getSisterDB("mydb").mycollection.find({},{_id : 0, partnerId , 1, id : 1}).min(chunk.min).max(chunk.max).count()
})
Run Code Online (Sandbox Code Playgroud)

但这太慢了,我的印象是它不使用我的分片键上的索引(打开{partnerId : 1, id : 1}).

我也用没有任何运气的解释取代了伯爵.我还用javascript forEach替换了count来手动计数(尝试使用不会命中磁盘的indexOnly查询).

我试图找到真正的大小,因为我已经看到几个块远远高于chunksize给出的提示(2Gb而不是64Mb).

sharding mongodb

8
推荐指数
2
解决办法
2938
查看次数

How do I convert a string text into a class name

I have a string as

classname = "Text"
Run Code Online (Sandbox Code Playgroud)

using this I want to create an object of the Text class

Now when I try doing this

classname = classname.constantize
Run Code Online (Sandbox Code Playgroud)

I get the Text as a module and not as a class. Please suggest something.

Thanks and regards

Rohit

ruby

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

Ruby字符串连接问题

这有效

irb(main):001:0> name = "Rohit " "Sharma"
=> "Rohit Sharma"
Run Code Online (Sandbox Code Playgroud)

但事实并非如此

irb(main):001:0> fname = "Rohit "
=> "Rohit "
irb(main):002:0> lname = "Sharma"
=> "Sharma"
irb(main):003:0> name = fname lname
Run Code Online (Sandbox Code Playgroud)

它给出了这个错误

NoMethodError: undefined method `fname' for main:Object
from (irb):3
Run Code Online (Sandbox Code Playgroud)

请提供一些建议.提前致谢.

UPDATE

得到答案后,我写了一篇博文.请检查一下.

ruby string

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

rails中的"puts"方法3

我一直在使用rails 3进行一些开发,我想知道为什么调用"puts"方法不会输出到标准输出.

我怎么得到这个?

ruby ruby-on-rails

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