运行rspec测试时出现以下错误
在rails中60秒(127.0.0.1:7055)无法获得稳定的firefox连接
使用最新的ruby(1.9.2)和firefox(6.0)
使用rspec-rails,capybara和其他几个宝石,但它们似乎不是问题.这些测试在另一个环境(linux)中运行良好.
我正在做一个rails项目,我想知道如何检查我是在代码中以开发人员模式还是生产模式运行?
谢谢
在ruby中(在服务器端)验证电子邮件地址的最佳/简单方法是什么?
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调用而不等待响应.
我正在开发一个混合了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/test到https://domain.com/test,但这是一个额外的重定向,加上它在表单帖子上失败了.
想法?
我想问一下哪个是将google地图集成到ruby on rails应用程序的最佳解决方案.特定的宝石是值得的还是我们应该为它写自己的观点?
感谢您的任何意见.
我是一个完整的菜鸟,建立我的第一个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)
谢谢您的帮助!
你知道如何在OpenLayers中有一个很好的聚类,比如这个谷歌的例子吗?
我有一个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)
所以,问题的重点是词汇和跆拳道,他们的意思是......(或点我到一些网站,我已经看了,但没有找到,解释如何工作的.)
这个问题太过分了吗?:)
我查看了教程http://guides.rubyonrails.org/configuring.html但它直接跳到了什么事情.
我认为我的用户工厂正在构建中存在问题.我收到一个错误,说密码不能为空,但它明确地设置在我的workers.rb中.有没有人看到我可能遗失的任何东西?或者为什么规范失败的原因?我为其他一个模型做了一个非常类似的事情,它似乎很成功.我不确定错误是否是由设计引起的.
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)
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)
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)
class User < ActiveRecord::Base
# …
Run Code Online (Sandbox Code Playgroud) ruby ×8
gmaps4rails ×2
config ×1
devise ×1
factory-bot ×1
firefox ×1
gmaps4rails2 ×1
google-maps ×1
http ×1
javascript ×1
mixpanel ×1
openlayers ×1
routes ×1
rspec ×1
ssl ×1