Cyril Duchon-Doris
Cyril Duchon-Doris

Reputation: 13949

Rails 4 & Mongoid : date helpers

We just migrated from rails ActiveRecord to mongoid. In our view we could use the helper

<%= f.date_select :date, :use_two_digit_numbers => true, :order => [:day, :month, :year], class: "form-control" %>

However it's not working with mongoid as it is sending the parameters

date(3i)"=>"21", "date(2i)"=>"9", "date(1i)"=>"2014"

And rails throw a

Mongoid::Errors::UnknownAttribute
Problem: Attempted to set a value for 'date(3i)' which is not allowed on the model

This question mentions that mongoid cannot do that without including a module. But apparently my rails app doesn't recognise the module ?

uninitialized constant Mongoid::MultiParameterAttributes

Upvotes: 3

Views: 873

Answers (2)

dayudodo
dayudodo

Reputation: 521

In the mongoid version 5, it looks like the multiple Parameter has been abandoned.

Now I use the html5 tag, like date_field_tag in the views, and in the controller action (create, update), I added a manual operation like @article.write_attribute(:published_on, params[:published_on]) before the object save to the database.

Although it is an ugly solution, it works.

Upvotes: 0

Cyril Duchon-Doris
Cyril Duchon-Doris

Reputation: 13949

Arf, just found this question that mentions it has been removed in mongoid 4. I'll use this gem then

https://github.com/netguru/mongoid-sadstory

But if you have other alternatives....

Upvotes: 1

Related Questions