小编use*_*595的帖子

YAML :: load引发未定义的类/模块错误

我正在我的rails应用程序中实现类似于纸张跟踪的功能.为了做到这一点,我在YAML中序列化对象.我有item_at_version方法,基本上做YAML::load(cached_object)- 这很好用,但是,我不知道为什么,有时它会返回undefined class/module _class name_.它适用于像Event,Conversation,Note等模型,但没有任何理由,它似乎为像Dataset,Comment,Student这样的模型抛出了这个错误(我试图找到任何模式,没有任何运气) .

我使用rails 3.2.8,ruby 1.9.3p327,psych作为YAML Engine(Psych :: Version返回1.3.4).

PS.当我在该文件的顶部添加require'model_name'时,它就像一个魅力.

任何想法我应该改变/添加什么来使这个工作?

编辑:我可以分享的代码不多:

def item_at_version
  YAML::load(cached_object)
end
Run Code Online (Sandbox Code Playgroud)

但也许回溯会很有趣:

~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:312:in `path2class'
~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:312:in `resolve_class'
~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:219:in `visit_Psych_Nodes_Mapping'
~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit'
~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept'
~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept'
~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:238:in `visit_Psych_Nodes_Document'
~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit'
~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept'
~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/psych/visitors/to_ruby.rb:20:in `accept'
~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/psych/nodes/node.rb:35:in `to_ruby'
~/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/psych.rb:128:in `load'
app/models/history_version.rb:7:in `item_at_version'
app/controllers/history_controller.rb:8:in `show'
actionpack (3.2.8) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.8) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.8) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.8) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.8) lib/active_support/callbacks.rb:502:in `_run__1697733322876708236__process_action__1122943786273335015__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback' …
Run Code Online (Sandbox Code Playgroud)

ruby yaml ruby-on-rails psych

9
推荐指数
1
解决办法
7726
查看次数

使用Ecto运行自定义sql查询

我正在玩Elixir&Ecto的东西.我想创建自定义SQL查询,它使用一些postgres特定的权限(在这种情况下:它搜索postgres数组).

这是我正在尝试做的事情:

iex(5)> query = from g in MyModel, where: "'sample_tag' = ANY(tags)", select: g    #Ecto.Query<from g in MyModel, where: "'sample_tag' = ANY(tags)", select: g>
iex(6)> Repo.all(query)                                                        [debug] SELECT g0."id", g0."name", g0."description", g0."image_file_name", g0."image_file_size", g0."image_updated_at", g0."image_content_type" FROM "my_model" AS g0 WHERE ('''sample_tag'' = ANY(tags)') [] (0.9ms)
Run Code Online (Sandbox Code Playgroud)

不幸的是,它正在逃脱(所以它应该产生......像这样:)

SELECT g0."id", g0."name", g0."description", g0."image_file_name", g0."image_file_size", g0."image_updated_at", g0."image_content_type" FROM "my_mode." AS g0 WHERE ('sample_tag' = ANY(tags))
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

elixir ecto

9
推荐指数
2
解决办法
3357
查看次数

SQL选择元素,其中字段的总和小于N.

鉴于我有一个包含以下内容的表,内容非常简单:

# select * from messages;
  id | verbosity 
 ----+-----------
   1 |        20
   2 |        20
   3 |        20
   4 |        30
   5 |       100
 (5 rows)
Run Code Online (Sandbox Code Playgroud)

我想选择N个消息,其中详细程度的总和低于Y(为了测试目的,假设它应该是70,那么正确的结果将是id为1,2,3的消息).这对我来说非常重要,该解决方案应该是独立于数据库的(至少应该在Postgres和SQLite上工作).

我试着用这样的东西:

SELECT * FROM messages GROUP BY id HAVING SUM(verbosity) < 70;
Run Code Online (Sandbox Code Playgroud)

但是它似乎没有按预期工作,因为它实际上并没有从详细列中汇总所有值.

我会非常感谢任何提示/帮助.

sql sqlite postgresql aggregate-functions sql-limit

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

Rails视图文件名中的自定义变量

默认情况下,Rails可以在文件名中找到格式,区域设置和模板语言的视图(所以我可以创建index.de.json.erb)

是否可以在视图的文件名中添加另一个自定义参数?

我想传递当前的子域,因此http://foo.example.com/将呈现index.foo.html.erb,http://bar.example.com/并将呈现index.bar.html.erb(两者都具有index.html.erb回退).

ruby-on-rails actionview

5
推荐指数
1
解决办法
556
查看次数

在全球范围内呈现Ember的视图

我是Ember世界的新手(来自Backbone/Marionette供电的应用程序),有些事情对我来说还不太清楚.

我想在我的应用程序中渲染3个视图:侧栏,导航和带有实际内容的视图(基于我的路径).

为了做到这一点,我添加到我的应用程序tempalate 3个出口:

<nav id="main_navigation">{{outlet navigation}}</nav>
<!-- some html goes here... -->
<nav id="sidebar_navigation">{{outlet sidebar}}</nav>
<section id="content">{{outlet}}</nav>
Run Code Online (Sandbox Code Playgroud)

因为我想在每个页面上显示它们,所以我使用以下代码创建了ApplicationRoute:

App.ApplicationRoute = Ember.Route.extend
  activate: ->
    @render "sidebar",
      outlet: "sidebar"
      # into "application"
Run Code Online (Sandbox Code Playgroud)

当然我有侧边栏模板,但我不认为它的代码在这里是相关的(我可以附加它,如果它是相关的).不幸的是,这会导致以下错误:

 Error while loading route: Error: Assertion Failed: An outlet (sidebar) was specified but was not found.
Run Code Online (Sandbox Code Playgroud)

如果我试着评论into "application",那么我得到这个:Error while loading route: TypeError: Cannot read property 'connectOutlet' of undefined

如果有人告诉我如何全局渲染这些模板(在所有页面上),我会非常高兴.

javascript coffeescript ember.js

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

Elasticsearch - 将id查询与must_not子句结合使用

我想将ids查询与must_not子句结合起来.我正在使用(重新)轮胎宝石与导轨应用.

我正在做这样的事情:

query do
  ids ["foo", "bar", "test"]
end
Run Code Online (Sandbox Code Playgroud)

哪个有效.但是,当我尝试将它与must_not子句组合时,我收到错误 - must_notboolean适用于范围,不包括ids查询.有没有办法将这两个查询结合起来?

ruby ruby-on-rails elasticsearch tire retire

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