graphql 的新手并开始使用 graphql。我有一个产品数据类型
type Product {
_id: String
name: String
price: Float
}
Run Code Online (Sandbox Code Playgroud)
我在 mongodb 中填充了一些产品
{ "_id" : ObjectId("5a61b31e009c0bef5d724a47"), "name" : "GROUND COFFEE", "price" : 3.06 }
{ "_id" : ObjectId("5a61b31e009c0bef5d724a48"), "name" : "PORK SAUSAGES 500g", "price" : 4.39 }
{ "_id" : ObjectId("5a61b31e009c0bef5d724a49"), "name" : "MILK UHT 1LT", "price" : 1.29 }
{ "_id" : ObjectId("5a61b31e009c0bef5d724a4a"), "name" : "HEINEKEN PREMIUM LIGHT 33CL", "price" : 1.61 }
Run Code Online (Sandbox Code Playgroud)
在graphiql中,我可以执行这样的查询
query {
products{
name,
price
}
}
Query result is
{ …Run Code Online (Sandbox Code Playgroud) 在rails 2中,我有一个lib/migration_helpers.rb文件,其中包含在db中设置和删除外键的方法.通过添加迁移文件,可以在迁移文件中的self.up和self.down中使用这些方法
require 'migration_helpers'
Run Code Online (Sandbox Code Playgroud)
在顶部,和
extend MigrationHelpers
Run Code Online (Sandbox Code Playgroud)
在课堂陈述后立即.
在rails 3中,这不起作用,如果我尝试使用migration_helpers.rb中的set_foreign_key方法运行迁移,则会引发以下错误:
== AddFkToArticles: migrating ================================================
-- set_foreign_key("articles", "book_id", "books")
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `set_foreign_key' for #<AddFkToArticles:0x000001034a1f38>
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)
我已经在config/application.rb中检查过,自动加载路径设置为包含lib.该文件是有效的,因为如果我注释掉require语句,那么rails会对丢失的'migration_helpers'文件抱怨.
我怀疑这是一个范围问题(rails 2使用"def self.up",rails 3使用"def change")但无法想象如何解决问题(现在我只是复制了迁移文件中的代码,只是为了检查它做它应该做的事情).
弗朗切斯科
我试图在rails应用程序中使用omniauth-twitter,但我一开始就陷入困境,无法弄清楚原因是什么.我确实在dev.twitter.com注册了我的应用程序,我得到了CONSUMER_KEY和CONSUMER_SECRET.为了缩短测试时间,我将这两个变量直接放在initializers/omniauth.rb中
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, "an_alphanumeric_code", "some_other_alphanumeric_code"
end
Run Code Online (Sandbox Code Playgroud)
在application.html.erb布局中,我有Twitter登录的链接
<%= link_to "Sign in with Twitter", "auth/twitter" %>
Run Code Online (Sandbox Code Playgroud)
但是当我点击登录时,我没有被重定向到Twitter登录
401 Unauthorized
Run Code Online (Sandbox Code Playgroud)
我已经在SO上检查了其他问题,这不应该是计算机时间问题(我的rails服务器时间设置正确).我怀疑问题在于没有可用于测试的公共IP和服务器名称.
是否有人能够从本地127.0.0.1:3000 rails服务器上运行omniauth-twitter?
在Rails 3应用程序布局中,我包括部分闪存消息.虽然在大多数情况下都可以,但有一个视图我需要在另一个地方出现flash消息; 有没有办法在layouts/application.html.erb中说出类似的东西
<%= render 'layout/messages' unless somecondition %>
Run Code Online (Sandbox Code Playgroud)
某些条件是能够检测到我在"myview/index"中的东西?