mongoid

Custom rails/mongoid relationship names not working

。_饼干妹妹 提交于 2019-12-11 23:08:56
问题 I'm trying to get custom relationship names to work in Mongo. A "collage" is a BSON document filled with BSON fields that are Work Ids. Here's what's in the database for "collage": Collage.create(slide_one: client.work.first.id, slide_two: client.work.second.id, slide_three: client.work.third.id) So, a collage is mongo record full of work Ids. I'd like to be able to write @collage.work_one or @collage.slide_one.work_one, or @collage.slide_one.work to get to the Work I want. Custom naming

Nested Attributes in ruby on rails

社会主义新天地 提交于 2019-12-11 21:58:05
问题 i want to create comments in ruby but i have problem 1) posts_controller.rb def comment Post.find(params[:id]).comments.create(params[:comment]) flash[:notice] = "Added your comment" redirect_to :action => "show", :id => params[:id] end 2)show.html.erb <%= form_tag :action => "comment", :id => @post %> <%= text_area "comment", "message" %><br /> <%= submit_tag "Comment" %> </form> 3)post.rb class Post include Mongoid::Document include Mongoid::Timestamps::Created include Mongoid::Timestamps:

Mongoid-peperclip [paperclip] Content Type Spoof: Error

心已入冬 提交于 2019-12-11 19:59:54
问题 I need to upload some large CSV files via mongoid-paperclip and I am getting error Uploaded file2 my_file has an extension that does not match its contents . In terminal I can see this error as [paperclip] Content Type Spoof: my_file.csv (["text/csv", "text/comma-separated-values"]), content type discovered from file command: application/octet-stream. See documentation to allow this combination. Ok, I set validation as do_not_validate_attachment_file_type :my_file It does not help same error.

FactoryGirl creates incomplete model

旧街凉风 提交于 2019-12-11 19:42:24
问题 Assume that I have a city model where: class city field :full_name, type: String # San Francisco, CA, United States field :_id, type: String, overwrite: true, default: ->{ full_name } end Assume that I have a factory defined in /spec/factories/cities.rb : FactoryGirl.define do factory :city do full_name 'San Francisco, CA, United States' end end Running the following code in one of the specs: city_attrs = { full_name: 'San Francisco, CA, United States' } City.create! city_attrs => #<City _id:

Rails/Mongoid: Parent object not recognising child of has_many/belongs_to relation after mongoimport

丶灬走出姿态 提交于 2019-12-11 19:09:11
问题 A CSV containing the following rows is imported into mongodb via CSV using the mongoimport tool: object_1_id,field1,field2 52db7f026956b996a0000001,apples,oranges 52db7f026956b996a0000001,pears,plums The fields are imported into the collection Object2 . After import the rows are confirmed to exist via the console. #<Object2 _id: 52e0713417bcabcb4d09ad12, _type: nil, field1: "apples", field2: "oranges", object_1_id: "52db7f026956b996a0000001"> #<Object2 _id: 52e0713517bcabcb4d09ad76, _type:

Mongoid::Versioning - delete one version

放肆的年华 提交于 2019-12-11 18:35:45
问题 I've a Rails model set up with Mongoid::Versioning. class Post include Mongoid::Document include Mongoid::Timestamps include Mongoid::Versioning field :name, type: String end I want to delete a specific older version. For eg. post = Post.create name: 'A' post.update_attributes name: 'B' post.update_attributes name: 'C' post.version #=> 3 post.versions.count #=> 2 first_version = post.versions.first #=> #<Post _id: , created_at: _, updated_at: _, version: 2, name: "B"> I want to delete first

Query based on calculated fields with Mongoid

女生的网名这么多〃 提交于 2019-12-11 18:29:16
问题 I want to implement a scope overdue in a model Invoice to return all invoices that exceeded the date, until they had to be paid. I have the fields invoice_date, :type => Date and days_for_payment, :type => Integer . In my previous version, which was built on ActiveRecord, I could use the query Invoice.where("invoice_date + days_for_payment < ?", Date.today) This query made the calculation on the DB side. Is there a way to get the same thing done with Mongoid? Or does anyone know a good

Rails 4 and mongoid: programmatically build a query with multiple AND and OR conditions

旧街凉风 提交于 2019-12-11 18:23:00
问题 I want to be able to dynamically transform an input hash like the following: { name: ['John', 'Luke'], status: ['ACTIVE', 'SUSPENDED'] } in a query that will put the different fields (name, status) in a AND relationship, and the values for each field in a OR relationship. In SQL that would be something like this: SELECT * FROM my_class WHERE (name LIKE 'John' OR name LIKE 'Luke') AND (status LIKE 'ACTIVE' OR status LIKE 'SUSPENDED') I've tried different approaches but I'm kind of stucked.

Mongoid is slow and shows this in the log: MONGODB cursor.refresh() for cursor 3474711247518436755

喜欢而已 提交于 2019-12-11 17:10:04
问题 I am using admin_assistant and have hacked on MongoDB support. The only issue now is that the index page queries are incredibly slow. admin_assistant uses will_paginate for these queries. I verified that the exact slow-down spot is where the will paginate collection is first accessed (.empty?). In the log I see the query, and after that I see these being slowly printed: MONGODB cursor.refresh() for cursor 3474711247518436755 MONGODB cursor.refresh() for cursor 3474711247518436755 MONGODB

Rails + MongoID + Simple Form in association: undefined method `options' for #<Mongoid::Relations::Metadata

僤鯓⒐⒋嵵緔 提交于 2019-12-11 16:27:21
问题 I have the following models which basically refer to Lessons and Categories. Each lesson can have one category, and each category is embedded in a lesson. class Lesson include Mongoid::Document field :title, :type => String field :category, :type => String field :price, :type => Integer field :description, :type => String field :user_id, :type => String validates_presence_of :title validates_presence_of :category validates_presence_of :price validates_presence_of :user_id validates