Rohit
Rohit

Reputation: 5721

Issue with dynamic fields in MongoDB

I am using mongodb in my rails application.

Suppose I have a mongo model as below

class Product
 include Mongoid::Document
   field :test, type: String
   field :link, type: String
end

Then it works fine

But when I add these fields dynamically by generating them in a lib or for example as below in my controller

params[:product][:test]="Test Value"
params[:product][:link]="Test Link"

Then I get the error as below Mongoid Error(Screenshot attached) Error ScreenShot

Please Help. Thanks in Advance.

Upvotes: 1

Views: 307

Answers (1)

mikdiet
mikdiet

Reputation: 10018

There is some private method test. In my project:

> Account.new.test
NoMethodError: private method `test' called for #<Account:0x007f89e60afd30>

> Account.new.send :test
ArgumentError: wrong number of arguments (0 for 2..3)

Upvotes: 1

Related Questions