Rohit
Rohit

Reputation: 5721

mongoid - Dynamic date/time attribute - MultiParameter Exception

I have a model named Form, which get fields as per user requirement, eg if user puts text field in the form then a attribute is created in Form model for storing string data.

Similarly I want to store date/time and datetime values. So I added

include Mongoid::MultiParameterAttributes

in the form model, because date and time values are submitted from for in multiple attributes.

But I get Mongoid::MultiParameterAttributes::Errors::MultiparameterAssignmentErrors exception in the controller create action, on the line @form = Form.new(params[:form])

def create
  @form = Form.new(params[:form])
  if @form.save
    redirect_to(form_path(@form))
  else
    redirect_to :action => "new"
  end
end

How do I get through this. Please Help

Upvotes: 1

Views: 579

Answers (2)

Tyler Brock
Tyler Brock

Reputation: 30136

The ruby driver can only serialize Time objects. That might be your problem.

Upvotes: 0

Jatin Ganhotra
Jatin Ganhotra

Reputation: 7025

Modify your Form class so it looks like the one below.

class Form
  include Mongoid::Document
  include Mongoid::MultiParameterAttributes

  ...
end

Upvotes: 1

Related Questions