小编apn*_*ing的帖子

无法在60秒内获得稳定的firefox连接(127.0.0.1:7055)

运行rspec测试时出现以下错误

在rails中60秒(127.0.0.1:7055)无法获得稳定的firefox连接

使用最新的ruby(1.9.2)和firefox(6.0)

使用rspec-rails,capybara和其他几个宝石,但它们似乎不是问题.这些测试在另一个环境(linux)中运行良好.

ruby firefox automated-tests ruby-on-rails ruby-on-rails-3

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

Rails - 如何在代码中检查开发人员模式或生产模式

我正在做一个rails项目,我想知道如何检查我是在代码中以开发人员模式还是生产模式运行?

谢谢

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

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

在Ruby中验证电子邮件地址的最佳/简便方法是什么?

在ruby中(在服务器端)验证电子邮件地址的最佳/简单方法是什么?

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

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

ruby中的异步http请求

 require 'net/http'

urls = [
  {'link' => 'http://www.google.com/'},
  {'link' => 'http://www.facebook.com/'},
 {'link' => 'http://www.yahoo.com/'}
]

urls.each do |u|
  u['content'] = Net::HTTP.get( URI.parse(u['link']) )
end

print urls
Run Code Online (Sandbox Code Playgroud)

这将作为程序代码.我只想打一个服务器,没有关于订单的问题.我怎么能在红宝石中做到这一点.一种选择是使用线程.

这是使用线程的示例.

require 'net/http'

urls = [
  {'link' => 'http://www.google.com/'},
  {'link' => 'http://www.facebook.com/'},
  {'link' => 'http://www.yahoo.com/'}
]

urls.each do |u|
  Thread.new do
    u['content'] = Net::HTTP.get( URI.parse(u['link']) )
    puts "Successfully requested #{u['link']}"

    if urls.all? {|u| u.has_key?("content") }
      puts "Fetched all urls!"
      exit
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

更好的解决方案.. ??

PS: - 我想点击mixpanel,这就是为什么我只想进行http调用而不等待响应.

ruby ruby-on-rails http ruby-on-rails-3 mixpanel

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

获取Rails URL帮助程序以自动输出https URL

我正在开发一个混合了http和https的网站 - 最简单/最简单的方法是让链接使用正确的路由协议 - 是否可以在路由文件中指定?

假设我在Rails 3中有以下路由.

match "/test" => "test#index", :as => :test, :constraints => { :protocol => 'https' }

如果我在http页面上,并且我使用test_url()它,它将输出http://domain.com/test.我想改为https://domain.com/test.

我知道我可以使用test_url(:secure => true),但那是重复的逻辑.

我知道我可以http://domain.com/testhttps://domain.com/test,但这是一个额外的重定向,加上它在表单帖子上失败了.

想法?

ruby ssl routes ruby-on-rails

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

Ruby on rails gem用于谷歌地图集成

我想问一下哪个是将google地图集成到ruby on rails应用程序的最佳解决方案.特定的宝石是值得的还是我们应该为它写自己的观点?

感谢您的任何意见.

ruby google-maps ruby-on-rails ruby-on-rails-3 gmaps4rails

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

Gmaps4rails V2 - 更改默认缩放

我是一个完整的菜鸟,建立我的第一个rails应用程序.我使用youtube上的apneadiving教程成功实现了Google-maps-for-rails V2:http://www.youtube.com/watch?v = R0l-7en3dUw&feature = youtu.be

我的问题是,对于我的每张地图,我只显示一个标记,当地图加载时,它会调整为完全缩放.

搜索周围,似乎有很多早期版本的Gmaps4rails解决方案,但对于V2,并通过javascript创建地图,我似乎无法找到一个有效的解决方案.

作为参考,我的代码如下:

视图:

    <script type="text/javascript">
      handler = Gmaps.build('Google');
      handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
      markers = handler.addMarkers(<%=raw @hash.to_json %>);
      handler.bounds.extendWith(markers);
      handler.fitMapToBounds();
      }); </script> 
Run Code Online (Sandbox Code Playgroud)

控制器:

def show
  @pins = Pin.find(params[:id])
  @hash = Gmaps4rails.build_markers(@pins) do |pin, marker|
    marker.lat pin.latitude
    marker.lng pin.longitude
  end
end
Run Code Online (Sandbox Code Playgroud)

我试图通过控制台使用:gmap.setzoom(12)进行更改,正如某些帖子所建议的那样,但是没有任何运气.

任何帮助深表感谢

对我有用的答案:将视图更改为:

  <script type="text/javascript">
  handler = Gmaps.build('Google');
  handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
  markers = handler.addMarkers(<%=raw @hash.to_json %>);
  handler.bounds.extendWith(markers);
  handler.fitMapToBounds();
  handler.getMap().setZoom(12);
  }); </script> 
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!

ruby-on-rails gmaps4rails ruby-on-rails-4 gmaps4rails2

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

OpenLayers,很棒的标记聚类

你知道如何在OpenLayers中有一个很好的聚类,比如这个谷歌的例子吗?

javascript openlayers markerclusterer

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

向我解释一下配置如何在Rails中运行

我有一个Rails 3应用程序,称之为"MyApp".在我的config\environments\production.rb文件中,我看到了这样的东西

MyApp::Application.configure do
  config.log_level = :info
  config.logger = Logger.new(config.paths.log.first, 'daily')
   ...or...
  config.logger = Logger.new(Rails.root.join("log",Rails.env + ".log"),3,20*1024*1024)
Run Code Online (Sandbox Code Playgroud)

所以,问题的重点是词汇和跆拳道,他们的意思是......(或点我到一些网站,我已经看了,但没有找到,解释如何工作的.)

  1. MyApp是一个模块?
  2. MyApp ::应用程序是......?什么,一个模块呢?
  3. MyApp :: Application.configure是一个方法吗?
  4. config是一个变量?我怎么在控制台中看到它?
  5. config.logger是一个???
  6. config.paths.log.first是...... - 在控制台我可以看到"MyApp :: Application.configure.config.paths.log.first",但不知道这意味着什么或如何从中提取信息!?!

这个问题太过分了吗?:)

我查看了教程http://guides.rubyonrails.org/configuring.html但它直接跳到了什么事情.

ruby config ruby-on-rails

22
推荐指数
2
解决办法
3770
查看次数

使用Rspec,Devise和Factory Girl测试用户模型

我认为我的用户工厂正在构建中存在问题.我收到一个错误,说密码不能为空,但它明确地设置在我的workers.rb中.有没有人看到我可能遗失的任何东西?或者为什么规范失败的原因?我为其他一个模型做了一个非常类似的事情,它似乎很成功.我不确定错误是否是由设计引起的.

Rspec错误

User should create a new instance of a user given valid attributes
Failure/Error: User.create!(@user.attributes)
ActiveRecord::RecordInvalid:
  Validation failed: Password can't be blank
# ./spec/models/user_spec.rb:28:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)

Factories.rb

Factory.define :user do |user|
  user.name                   "Test User"
  user.email                  "user@example.com"
  user.password               "password"
  user.password_confirmation  "password"
end
Run Code Online (Sandbox Code Playgroud)

user_spec.rb

require 'spec_helper'

describe User do
  before(:each) do
    @user = Factory.build(:user)
  end

  it "should create a new instance of a user given valid attributes" do
    User.create!(@user.attributes)
  end
end
Run Code Online (Sandbox Code Playgroud)

user.rb

class User < ActiveRecord::Base
  # …
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails devise factory-bot

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