Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

user.wholesaler.created_at throws error on Account page #12

Closed
patrickmcelwee opened this issue Feb 1, 2012 · 5 comments
Closed

user.wholesaler.created_at throws error on Account page #12

patrickmcelwee opened this issue Feb 1, 2012 · 5 comments

Comments

@patrickmcelwee
Copy link

Great extension! We're hoping to make good use of it. I am working with the 0.60.x branch.

When logged in as a wholesaler and going to "My Account," the extension throws the error: undefined method `created_at' for "#Wholesaler:0xb57f85a4":Wholesaler

This comes from line 4 of spree_wholesale-bab7a33485ad/app/views/hooks/_wholesale_customer.html.erb:
<h4 class="wholesale-customer-id"><%= t('wholesale_customer_since', { :time => @user.wholesaler.created_at }) %></h4>

To get around the issue, I am just replacing @user.wholesaler.created_at with @user.created_at

Is it normal that my Wholesaler objects do not include a "created_at" field?

@citrus
Copy link
Owner

citrus commented Feb 9, 2012

Hi sorry for the delay, I just got back from vacation :)

This is a strange bug as wholesalers should have a created at field... Have you tried running the upgrade generator? rails g spree_wholesale:upgrade then run rake db:migrate

This generator should reset the wholesalers' created at fields...

@patrickmcelwee
Copy link
Author

I'm a big fan of vacations :-)

I think you are right: that I had never run that. But, when I ran the
migration, I got the error:

Mysql2::Error: Can't DROP 'created_at'; check that column/key exists: ALTER
TABLE wholesalers DROP created_at

I am wondering whether there is an error in the UpgradeSpreeWholesale
migration - or maybe it is just an error for me since I am inexplicably
missing those db columns - but I wanted to check with you in case I am
missing something:

def self.up
remove_column :wholesalers, :created_at # I THINK I SHOULD DELETE THIS
LINE
remove_column :wholesalers, :updated_at # AND THIS ONE
add_column :wholesalers, :created_at, :datetime
add_column :wholesalers, :updated_at, :datetime
Wholesaler.all.each do |wholesaler|
wholesaler.created_at = wholesaler.user.created_at
wholesaler.save
end
end

def self.down
remove_column :wholesalers, :created_at
remove_column :wholesalers, :updated_at
end

Thanks,

Patrick

On Thu, Feb 9, 2012 at 11:44 AM, Spencer Steffen <
reply@reply.github.com

wrote:

Hi sorry for the delay, I just got back from vacation :)

This is a strange bug as wholesalers should have a created at field...
Have you tried running the upgrade generator?
rails g spree_wholesale:upgrade

This generator should reset the wholesalers' created at fields...


Reply to this email directly or view it on GitHub:
#12 (comment)

@citrus
Copy link
Owner

citrus commented Feb 9, 2012

Commenting out those two lines should allow you to add the created_at and updated_at columns... give it a try and let me know how it goes :)

@patrickmcelwee
Copy link
Author

OK ... I went ahead and commented out those lines and it seems to work without problems. Thanks for your help!

@citrus
Copy link
Owner

citrus commented Feb 9, 2012

You're welcome! Glad it worked out for ya :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants