C Barbaza
C Barbaza

Reputation: 65

rails app - mongoid does not insert a new field

I just started to create on app with rails-api and mongoDB (gem mongoid in rails).

I have created my model like this:

class User 
    include Mongoid::Document
    include Mongoid::Timestamps

    embeds_many :language
    accepts_nested_attributes_for :language

    field :name, type: String
    field :lastname, type: String
    field :mail, type: String
    field :passwd, type: String
    field :auth_token, type: String
end

And i want to add another field in my model.

So at the end of my model i add this:

field :slug, type: String

But when i insert a new document, mongoid doesn't detect the new field and return null.

I try to do rake:migration but is useless with mongodb and i can't find the issue. Could you help me?

Best regards

Upvotes: 0

Views: 1432

Answers (1)

Uzbekjon
Uzbekjon

Reputation: 11813

Most probably you did not add that new field into your strong params whitelist.

Look into your controller and find a line that looks like this:

params.require(:user).permit(:name, ...)

Add slug there like this:

params.require(:user).permit(:name, ..., :slug)

Upvotes: 4

Related Questions