Tag: mongoid

当我将我的应用程序推送到Heroku时,为什么我收到错误500“我们很抱歉,但出了点问题”?

我把我的应用程序推到了Heroku,我得到了“我们很抱歉,但出了点问题(500)”为什么会这样? 我知道错误消息来自我在/ public目录中的一个标题为500.html的文件,但我不确定为什么会这样。 我的heroku日志和我的mongoid.yml文件一样。 谢谢。 Heroku日志: 2014-02-23T02:12:14.311710+00:00 heroku[router]: at=info method=GET path=/ host=danacamilleapp.herokuapp.com request_id=25556ae0-c4ac-40f7-8008-bd8860b87039 fwd=”72.89.235.136″ dyno=web.1 connect=27ms service=18ms status=500 bytes=932 2014-02-23T02:12:14.311277+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/mongoid-3.1.6/lib/mongoid/sessions.rb:171:in `collection’ 2014-02-23T02:12:14.311277+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/mongoid-3.1.6/lib/mongoid/sessions.rb:137:in `with_name’ 2014-02-23T02:12:14.311520+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/mongoid-3.1.6/lib/mongoid/contextual.rb:34:in `context’ 2014-02-23T02:12:14.311277+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/mongoid-3.1.6/lib/mongoid/sessions/factory.rb:28:in `create’ 2014-02-23T02:12:14.311277+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/mongoid-3.1.6/lib/mongoid/sessions/factory.rb:122:in `inject_ports’ 2014-02-23T02:12:14.311520+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/mongoid-3.1.6/lib/mongoid/contextual/mongo.rb:260:in `initialize’ 2014-02-23T02:12:14.311520+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `__run_callback’ 2014-02-23T02:12:14.311520+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/mongoid-3.1.6/lib/mongoid/contextual.rb:19:in `first’ 2014-02-23T02:12:14.311698+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.16/lib/action_controller/metal/rescue.rb:29:in `process_action’ […]

使印象派gem适应mongoid

我正在尝试修改这个gem, https://github.com/charlotte-ruby/impressionist到mongoid odm。 我在https://github.com/tute/impressionist/commit/1c3f809da8ebd3ced8cb9bda8caee89012091a10中看到了对mongo_mapper的提交。 这是mongoid的impression.rb模型: class Impression include Mongoid::Document include Mongoid::Timestamps::Created field :impressionable_type, :type => String field :impressionable_id, :type => String field :user_id, :type => String field :controller_name, :type => String field :action_name, :type => String field :view_name, :type => String field :request_hash, :type => String field :ip_address, :type => String field :session_hash, :type => […]

Mongoid和载波

为了保持DRY,我有一个包含Mongoid文档的ModelBase类,如下所示: class ModelBase include Mongoid::Document alias_attribute :guid, :id def as_json(options = {}) azove_hash = options.merge(:methods => :guid) super azove_hash end end 然后我的所有模型都inheritance自ModelBase,它们似乎工作正常。 但是,有一种模型我使用CarrierWave。 当它inheritance自ModelBase时,对mount_uploader的调用失败。 当我将模型包含在内部而没有子类化时,它可以正常工作。 是不是可以在inheritance自另一个类的类中使用carrierwave? 这是失败的类的版本。 会很感激任何建议/想法 require ‘carrierwave/orm/mongoid’ class SomeOtherModel true field :category validates :category, :presence => true, :inclusion => {:in => %w{audio graphics text video}} field :content_uri validates :content_uri, :presence => true […]

Carrierwave_Direct的direct_upload_form_for为FileUploader返回未定义的方法`model_name’:Class

我一直在努力解决这个问题几个小时了。 在我的视图中使用carrierwave_direct的direct_upload_form_for时,它会返回以下错误: FileUploader Carrierwave类: class FileUploader < CarrierWave::Uploader::Base include CarrierWaveDirect::Uploader end 手动文件模型: class ManualFile include Mongoid::Document mount_uploader :file, FileUploader field :name, :type => String end UploadController: class UploadController < ApplicationController def manual_new @uploader = ManualFile.new.file @uploader.success_action_redirect = upload_edit_path end def manual_edit @myfile = ManualFile.new(key: params[:key]) end end 我的看法: 我无法理解我做错了什么。 我试图跟随这个railscast 。 我正在使用Ruby 1.9.3,Rails 3.2.3,Mongoid 3和载波波gem指向github […]

在mongoid db中采用vs distinct。 哪个更快?

似乎mongodb有两个等价的方法: #pluck和#distinct都只返回集合中的给定字段。 所以两者 User.pluck(:name) User.distinct(:name) 将从db中的User集合返回所有名称的数组 > [‘john’, ‘maria’, ‘tony’, ‘filip’] 我不介意重复。 哪种方法更快?

我可以在ActiveRecord(或Mongoid)中为数据库连接和table_name配置线程安全的每个请求配置吗?

又称<> 环境 我的应用程序是这样建模的: user has_many databases database has_many tables table has_many rows row habtm(+value) columns 你明白了! 因此,我希望不是在数据库内建模数据库,而是: 一个包含用户和的用户的sqlite3数据库 每个用户都有许多sqlite数据库 每个用户都会在他的数据库中LCRUD他的表(类似于phpmyadmin) 问题 我想为数据库连接和table_name提供线程安全的每请求配置 class Table < ActiveRecord::Base end # in some controller # set the connection to the user-selected database from some DB list Table.connection = current_user.session.connection # set the name to the user-selected table from […]

使用带有rails 3和dry_crud的Mongoid时替换column_names

我一直在Rails 3和Mongoid上飙升,并且在Grails的自动脚手架的愉快记忆中,当我发现时,我开始寻找ruby的DRY视图: http : //github.com/codez/dry_crud 我创建了一个简单的类 class Capture include Mongoid::Document field :species, :type => String field :captured_by, :type => String field :weight, :type => Integer field :length, :type => Integer def label “#{name} #{title}” end def self.column_names [‘species’, ‘captured_by’, ‘weight’, ‘length’] end end 但是由于dry_crud依赖于self.column_names并且上面的类不inheritance自ActiveRecord :: Base,我必须为column_names创建我自己的实现,如上所述。 我想知道是否可以创建一个默认实现,返回上面的所有字段,而不是硬编码列表?

Mongoid找到嵌入式文件

我正在尝试通过其id搜索嵌入的文档,并将其返回。 这是可能的,但据我所知,只有通过使用mongo找到嵌入它的文档,然后在ruby中搜索我所追求的嵌入文档的文档。 像这样: # commenter.rb def post # todo: find syntax do avoid double query if user = User.any_of({‘posts.commenter_ids’ => self.id}).last user.posts.where(‘commenter_ids’ => self.id).last end end 看起来很简单,但我没有在google / SO搜索中找到任何我喜欢的东西。 思考?

Mongoid不和工厂玩得很好

在我的测试中,Moingoid似乎没有持久地设置嵌入式关系。 在我的用户模型中,我有: def vote_on(账单,价值) 如果my_groups = self.groups my_groups.each做| g | bill.votes.create(:value => value,:user_id => self.id,:group_id => g.id) #结果只有工厂:bill.votes.first.group = nil #和bill.votes.first.user = nil !! #self.id和g.id在测试期间有很好的价值,他们只是不坚持 结束 其他 提出“此用户没有群组”## {self.full_name}“ 结束 结束 其他有用的代码可能是: ##账单模型 class比尔 embeds_many:投票 ##投票模型 投票 包括Mongoid :: Document field:value,:type =>符号#可以是:aye,:nay,:abstain #field:group_type,:type => Integer belongs_to:用户 belongs_to:group embedded_in:bill 结束 ## test 测试“描述性记录应该工作”做 user1 = Factory.build(:user) […]

mongodb:获取特定文件的最佳方式,然后是其他文件

假设我有1000个文件,每个文件都有: user_id text 现在,我想提取所有这些文档,但首先从几个特定用户(给定一组用户ID)中提取文档,然后是所有其他文档。 我想如果user_id存在于特定用户数组中(使用范围传递数组)然后对该新属性进行排序,则使用map reduce创建新的权重内联属性。 但是根据我的理解,你无法在map reduce之后进行排序。 任何人都有一个很好的建议如何解决这个问题? 任何建议都将受到欢迎。 谢谢!