我正在使用以下内容:
Rails 4.1.1
guard-zeus 2.0.0
rspec-rails 3.0.1
Run Code Online (Sandbox Code Playgroud)
开箱即用默认值rails g rspec:install和guard init
当我运行guard并保存规范文件时,出现错误:
undefined method `configure` for RSpec:Module (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
我可以使用rspec spec和rake来运行规格。
在 中spec_helper,如果我require 'rspec/rails在配置块之前,防护工作正常,但随后rspec spec失败并出现错误:
uninitialized constant ActiveSupport::Autoload (NameError)
Run Code Online (Sandbox Code Playgroud)
rails_helper我猜现在和是分开的,加载顺序有问题spec_helper
。
两个问题:
您只需回答一个问题。
这应该很简单.我想以这种方式在Ruby中重复一个字符串:
def repeat(input, n)
n.times input
end
Run Code Online (Sandbox Code Playgroud)
问题是,我需要在inputs 之间添加空格,而不是在最后一次输入后添加空格.
我需要构建一个带有重复属性的逻辑查询,但无法使其工作.我有一个主题列表对象.
topics = [u'string1', u'string2', ...]
Run Code Online (Sandbox Code Playgroud)
我有一个查询对象:
videos = Video.query()
videos.count()
=> 19
Run Code Online (Sandbox Code Playgroud)
主题是重复的字符串属性
class Video
topics = ndb.StringProperty(repeated=True)
Run Code Online (Sandbox Code Playgroud)
我想要返回有主题string1OR的视频string2.我之前也不知道列表对象的长度,或者我可以用逻辑运算符来构建查询.
我尝试这样做就像文档建议的那样
videos.filter( Video.topics.IN([topics]) )
Run Code Online (Sandbox Code Playgroud)
但是会抛出IN期望字符串而不是列表对象的错误.
我该怎么做呢?
我不知道如果我构建的查询与AND和OR正确.当我查询匹配标签时,我会收到一些匹配的视频.但是当我尝试第二个查询时,(为了确保视频与自身无关),查询将返回所有视频.
更新:我希望返回至少包含一个相同标签的视频video,但返回的列表不包含video.基本上是一个related_videos功能.
from solveforx.lib.moonshots import Video
from google.appengine.ext import ndb
video = Video.query().get()
tags = video.tags or []
for tag in tags:
print Video.query(Video.tags == tag).count() # returns 1
print "-------"
print Video.query(Video.tags == tag and Video.key != video.key) # returns total videos - 1
print "========"
# also tried this
# print Video.query(Video.tags == tag, ndb.AND(Video.key != moonshot.key)).count() # returns 0
# print Video.query(ndb.AND(ndb.AND(Video.tags == tag), ndb.AND(Video.key != video.key) )).count() …Run Code Online (Sandbox Code Playgroud) 当我通过needs API访问控制器的内容时,如何访问itemController的属性?
App.PostsIndexController = Ember.ArrayController.extend
itemController: 'post'
someAction: -> console.log("i'm melting!")
App.PostController = Ember.ObjectController.extend
someComputedProperty: (-> true ).property()
App.IndexController = Ember.Controller.extend
needs: ['postsIndex']
Run Code Online (Sandbox Code Playgroud)
<script type="text/x-handlebars" data-template-name="index">
{{#each post in controllers.postsIndex.content}}
{{someComputedProperty}}
<a {{action someAction target="postsIndex"}}>click</a>
{{/each}}
</script>
Run Code Online (Sandbox Code Playgroud)
我试过{{controllers.postsIndex.someComputedProperty}}并{{someComputedProperty}}在index模板中.
我想在Ruby中运行后台服务,每天一次发布到我的Facebook页面.最好的方法是什么?我已经阅读了图谱API,但他们的大部分文档依赖于首先请求用户的权限.如何为我自己使用而不是我的应用的最终用户授予这些权限?例如,Twitter为您提供身份验证令牌以连接到您自己的帐户.
关于Graph API的许多答案都已过时.我正在使用Ruby,所以任何有关宝石或其网站上的任何SDK的建议.
更新
感谢@oldergod的回复.我有一个更新的问题.
当我这样做,我能张贴作为myPageName对myPageName的墙上.
@graph.put_connections("myPageName", "feed", :message => "I am writing on my wall!")
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时:
@graph.put_connections("me", "feed", :message => "I am writing on my wall!", :link => "http://google.com")
Run Code Online (Sandbox Code Playgroud)
它发布myPageName为me
我究竟做错了什么?我已经请求了manage_pages权限.
如何/search一次性将端点添加到所有这些资源?
MyCoolApp::Application.routes.draw do
resources :posts, only [:index, :show, :create] do
collection { get :search }
end
resources :authors, only [:index, :show] do
collection { get :search }
end
resources :comments, only: [:index, :show] do
collection { get :search }
end
resources :categories, only: [:index, :show] do
collection { get :search }
end
resources :tags, only: [:index] do
collection { get :search }
end
end
Run Code Online (Sandbox Code Playgroud)
我看到这个答案很接近,但我需要能够为触及资源指定操作.有更好的方法以更好的方式注入搜索路径吗?
%w(one two three four etc).each do |r|
resources r do
collection …Run Code Online (Sandbox Code Playgroud) 我无法确定原因,但我收到了在Rails项目中多次加载共享规范的弃用警告.以下是它们的定义方式:
#spec/support/shared/authenticated_endpoints_spec.rb
RSpec.shared_examples "an authenticated endpoint" do
it_behaves_like "an authenticated show endpoint"
it_behaves_like "an authenticated index endpoint"
end
RSpec.shared_examples "an authenticated show endpoint" do
# omitted
end
RSpec.shared_examples "an authenticated index endpoint" do
# omitted
end
Run Code Online (Sandbox Code Playgroud)
我spec_helper看起来像这样:
RSpec.configure do |config|
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
end
Run Code Online (Sandbox Code Playgroud)
这是我得到的弃权警告:
WARNING: Shared example group 'an authenticated endpoint' has been previously defined at:
/Users/me/my_proj/spec/support/shared/authenticated_endpoints_shared_spec.rb:1
...and you are now defining it at:
/Users/me/my_proj/spec/support/shared/authenticated_endpoints_shared_spec.rb:1
The new definition will overwrite the original one.
WARNING: …Run Code Online (Sandbox Code Playgroud) 以下技术的优点和缺点是什么?
编辑:以下技术之间有什么区别?**
我正在寻找与性能,灵活性,可读性等相关的差异.其中一些事情比其他事情更明显.
class Foo
def my_method(name)
case name
when "a"
"a"
when "b"
"12312"
when "c"
"blahblah"
when "d"
"---------"
when "e"
1
when "f"
:reference
end
end
end
Run Code Online (Sandbox Code Playgroud)
VS
class Foo
MY_HASH = {
"a" => "a",
"b" => "12312",
"c" => "blahblah",
"d" => "-------",
"e" => 1,
"f" => :reference
}
def my_method(name)
MY_HASH[name]
end
end
Run Code Online (Sandbox Code Playgroud) 我正在尝试将水平规则添加为div容器中的最后一项。我试过了
<script>
var rule = '<hr />';
$('#content-nav').append(rule);
</script>
Run Code Online (Sandbox Code Playgroud)
我将此代码添加到我网站的header.php部分,该部分使用php include添加到多个php文件中。但是jQuery文件也已添加,并且对于已实现的其他jQuery插件也能正常工作。
我不确定我的html js应该去哪里。我把这个放错地方了吗?还是代码有问题?
你能告诉我这个config.php文件有什么问题吗?我认为我的语法在某处错了.我想检查环境变量SERV_ENV以查看该值是否为local,然后根据该变量设置BASE_URL变量.
<?php
if (getenv('SERV_ENV')='local'); {
$BASE_URL = "/001_Current_Projects/collegedesis/"
else
$BASE_URL = "/"
end
}
?>
Run Code Online (Sandbox Code Playgroud) ruby ×3
rspec ×2
config ×1
ember.js ×1
facebook ×1
guard ×1
html ×1
if-statement ×1
javascript ×1
php ×1
rspec-rails ×1
zeus ×1