Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment of multiparameter attributes #15

Open
nomasprime opened this Issue Aug 11, 2014 · 7 comments

Comments

Projects
None yet
4 participants
@nomasprime
Copy link

commented Aug 11, 2014

Newish to Rails, followed the docs but getting the following error:

4 error(s) on assignment of multiparameter attributes [error on assignment [11, 8, 2014] to start_date (undefined method `klass' for nil:NilClass),error on assignment [12, 8, 2014] to end_date (undefined method `klass' for nil:NilClass),error on assignment [2014, 8, 11, 7, 45] to start_time (undefined method `klass' for nil:NilClass),error on assignment [2014, 8, 11, 8, 45] to end_time (undefined method `klass' for nil:NilClass)]

Code - https://gist.github.com/habitullence/533730edef77f4e1a48a

@robertgauld

This comment has been minimized.

Copy link
Collaborator

commented Aug 11, 2014

Please can you share the code you're using which generates those errors.

@nomasprime

This comment has been minimized.

Copy link
Author

commented Aug 11, 2014

Hi @robertgauld, I've created a gist and updated the description.

@robertgauld

This comment has been minimized.

Copy link
Collaborator

commented Aug 11, 2014

Can you humor me and make the following chnage, it shouldn't make a difference but it just might.

# app/models/event.rb
class Event < ActiveRecord::Base
    date_time_attribute :start
    date_time_attribute :end
end
@einzige

This comment has been minimized.

Copy link
Owner

commented Aug 12, 2014

@robertgauld we can easily start from specs here :)

@nomasprime

This comment has been minimized.

Copy link
Author

commented Aug 13, 2014

@robertgauld negatory, same error.

@ridget

This comment has been minimized.

Copy link

commented Sep 30, 2014

+1 getting same error here. Also using separate date and time selects.

@ridget

This comment has been minimized.

Copy link

commented Sep 30, 2014

fyi: http://arjanvandergaag.nl/blog/rails_attributes_magic.html gives a good run down on whats going on, rails is just assigning these virtual attributes as strings.

@habitullence There's a way around this:

in your case:

# app/models/event.rb
class Event < ActiveRecord::Base
  date_time_attribute :start, :end

   self.columns_hash['start_time'] = OpenStruct.new(type: :time, klass: Time)
   self.columns_hash['start_date'] = OpenStruct.new(type: :date, klass: Date)
   self.columns_hash['end_time'] = OpenStruct.new(type: :time, klass: Time)
   self.columns_hash['end_date'] = OpenStruct.new(type: :date, klass: Date)

end

You can alternatively swap out the OpenStruct for something like : ActiveRecord::ConnectionAdapters::Column.new("expiration_date", nil, "date")

Be sure to not have ignore_date as part of your options on your time select, or you will run into the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.