mongoid

Adding button click counter in rails 3

泪湿孤枕 提交于 2019-12-09 20:54:30
问题 I want to add buttons on my article so that I can know the number of times its clicked and update counter on the database, I am using mongoid ,my model is: class Article include Mongoid::Document include Mongoid::Timestamps field :title, :type => String field :content, :type => String field :likes, :type => Integer ,:default => 0 field :dislikes, :type =>Integer, :default => 0 field :spam, :type => Integer, :default => 0 end My articles show controller is: def show @article = Article.find

ruby on rails 5.0.0.2 incompatible and conflict with gem mongoid

心不动则不痛 提交于 2019-12-09 15:54:09
问题 ruby version 2.3.0 rails version 5.0.0.beta2 **GEMFILE ** source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '>= 5.0.0.beta2', '< 5.1' #mongoid gem gem 'mongoid', '~> 5.1.0' # Use Puma as the app server gem 'puma' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.1.0' # See https:/

Recurring rails error on Heroku/Unicorn - 'execution expired', an ActionView::Template::Error

北慕城南 提交于 2019-12-09 14:54:37
问题 My question is similar to the following, but is happening under slightly different circumstances. Rails: execution expired on time_zone_select My setup is: Rails 3.2.13 Unicorn 4.6.2 Mongoid 3.0.22 Moped 1.4.2 Running on Heroku Cedar. MongoDB is hosted at MongoLab. The errors come in batches and are often solved by a Heroku process restart. The first is usually the one below: An ActionView::Template::Error occurred in [controller]#[action]: execution expired vendor/bundle/ruby/1.9.1/gems

Dynamic hash field in Mongoid using strong parameters

╄→尐↘猪︶ㄣ 提交于 2019-12-09 11:51:41
问题 So there doesn't appear to be any clean way to generically allow Hash field with strong parameters. This may of course be a strong parameters issue but I'm curious if there is a workaround. I have a model with some fields... field :name, type: String field :email, type: String field :other_stuff, type: Hash, default: {} Now I could just permit everything: params.require(:registration).permit! But that isn't really a great idea and what I'd like to do is something like... params.require(

How to do proper database testing (TDD) on Rails 3 using MongoDB and Mongoid

為{幸葍}努か 提交于 2019-12-09 04:20:20
问题 How would go about writing proper unit testing (and integration testing for that matter) using MongoDB through Mongoid on Rails ? I am asking, because to the opposite of using let's say SQLite3, even when running tests, everything I do does persists. So for the moment I am writing the creation test and then I manually delete everything I do. But it's getting annoying and even complicated to do for integration testing. Sample of what I do: before(:each) do @user = User.create!(@attr) end after

undefined method page for #<Array:0xc347540> kaminari “page” error. rails_admin

回眸只為那壹抹淺笑 提交于 2019-12-08 20:57:33
i am using rails_admin. when i go to certain resource. by typin url localhost:3000/admin/rule than it give me this error. code is: scope = Rule.all scope.page(1).per(2) . above code is writtten in rails_admin gem.in a file named mongoid.rb placed in adaptors folder. complete log is: NoMethodError (undefined method `page' for #<Array:0xcea7408>): mongoid (2.4.8) lib/mongoid/criteria.rb:385:in `method_missing' /home/usman/.rvm/gems/ruby-1.9.2-p290@system/bundler/gems/kaminari-809105ad782a/lib/kaminari/models/mongoid_extension.rb:11:in `page' /home/usman/.rvm/gems/ruby-1.9.2-p290@system/bundler

Mongoid: how to query for all objects where value is nil?

回眸只為那壹抹淺笑 提交于 2019-12-08 15:13:23
问题 I'm having a difficult time doing something such as: Something.where(:field => nil) or Something.where(:field => { '$eq' => nil }) What's the right way to handle this in Mongoid? 回答1: That's the right way to do it. To find cars whose engine is nil , for example, use: # Cars that have a _nil_ engine. Car.where(:engine => nil) If you're trying to look for the absence of a field (rather than one that's set to nil ), use the $exists predicate: # Cars that lack an engine entirely. Car.where(

Need suggestions on designing artist recommendation

徘徊边缘 提交于 2019-12-08 15:05:11
问题 I have the following scenario.I need to recommend artists to users. How should this be modeled? I am looking for suggestions on this. I was thinking. Based on following criterias: When a user listens to a song, the songs genre gets recorded somewhere with +1 When a user "likes" a song, the songs genre gets recorded somewhere with +2 This way I could list all artists based on the genre that has the highest points. Even still, should I have a new model called "Recommendation" and have it

How do I find an object whose properties foo or bar equal a query value?

99封情书 提交于 2019-12-08 15:04:13
问题 I searched google and looked at the docs, but I found no example of this. I have this object with embedded children: { teacher: "Balthazar", students: [ { name: 'Wilfred', sibling: 'Cordelia' }, { name: 'Mortimer', sibling: 'Arthur' }, { name: 'Cordelia', sibling: 'Wilfred' }, { name: 'Arthur' sibling: 'Mortimer' }, ] } I want to find Balthazar 's students whose name or sibling is in ['Wilfred', 'Cordelia', 'foo'] . I got it to work this way: criteria_a = balthazar.students.in(name: ['Wilfred

What are good ways to get current user detail in models?

戏子无情 提交于 2019-12-08 14:45:51
问题 I used devise gem for authentication in my rails application. I want to get certain information about current user on after_create callback. How is it possible? My model code is: class Department field :name after_create :create_news private def create_news @user = current_user end end But when I create new department I get following error. undefined local variable or method `current_user' for #<Department:0x00000005b51648> What is the best way for this? 回答1: Access control in rails is done