我尝试使用此命令运行localtunnel:
localtunnel 3000
Run Code Online (Sandbox Code Playgroud)
并得到此错误:
[Error] Unable to register tunnel. Perhaps service is down?
Run Code Online (Sandbox Code Playgroud)
服务是否已关闭,或者我可以做些什么来解决它?
所以我试图将'votes'列的默认值设置为0,但是当我在rails c或单元测试中创建答案的实例时,投票值总是如此nil.关于为什么这不起作用的任何想法?
我这样改变了迁移:
class AddVotesToAnswers < ActiveRecord::Migration
def change
add_column :answers, :votes, :integer, default: 0
end
end
Run Code Online (Sandbox Code Playgroud)
这是模型:
class Answer < ActiveRecord::Base
attr_accessible :is_correct, :question_id, :title, :sms_answer_code, :votes
belongs_to :question
def upvote
self.votes += 1
end
end
Run Code Online (Sandbox Code Playgroud)
测试规格
需要'spec_helper'
describe Answer do
before do
@answer = Answer.make!
end
it "should have a default vote value of zero" do
binding.pry
@answer.votes.should eq(0)
end
end
Run Code Online (Sandbox Code Playgroud) 我正在寻找像Python这样的if-in语句。
从本质上讲,如果x 在 an_array做
这是我正在处理的代码,其中“ line”变量是一个数组。
def distance(destination, location, line)
if destination and location in line
puts "You have #{(n.index(destination) - n.index(location)).abs} stops to go"
end
end
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个条形图,其中包含D3中xAxis上每个条形的自定义值,并且我认为我会尝试使用tickValues.只是尝试一下,我给它一些虚拟数据,但它不能像这样工作:
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.tickValues(['hi','b','c','d','e']);
Run Code Online (Sandbox Code Playgroud)
这是xScale:
gon.votes.length是每个答案的总票数的数组,并且在功能上只返回特定调查问题将有多少条(这是一个调查应用程序fyi)
var xScale = d3.scale.linear()
.domain([0,gon.votes.length])
.range([0,w]);
Run Code Online (Sandbox Code Playgroud)
最后,当我打电话
function(d){ return d.title}
Run Code Online (Sandbox Code Playgroud)
这将为每个条形图提取适当的标题.
此处还有渲染的xAxis的刻度线的html:NaN
有关如何将其放在xAxis上的任何提示?是否试图修改错误的方法?
我有一个我正在尝试测试的课程,其中包括ActiveModel::Validations
module SomeModule
class SomeClass
include ActiveModel::Validations
end
end
Run Code Online (Sandbox Code Playgroud)
我试图在不spec_helper保持快速的情况下测试它,但require 'activemodel'规范顶部的简单方法不起作用。我不断收到一个uninitialized constant SomeModule::SomeClass::ActiveModel(NameError). 对于规格文件:
require 'activemodel'
describe SomeModule::SomeClass do
end
Run Code Online (Sandbox Code Playgroud)
有什么解决这个问题的建议吗?提前致谢!
activemodel ×1
activerecord ×1
arrays ×1
bar-chart ×1
d3.js ×1
hosting ×1
if-statement ×1
javascript ×1
localtunnel ×1
migration ×1
rspec ×1
ruby ×1
tdd ×1