In ActiveAdmin Gem, how to add invitation count to

2019-08-28 05:34发布

In my project I have implemented , which is integrated with devise invitable. So in my application admin can invite a customer through an email. While inviting, i'm getting the following error:

*ActiveRecord::StatementInvalid in Admin::CustomersController#send_invitation
Mysql2::Error: Unknown column 'invitations_count' in 'field list': UPDATE `admin_users` SET `invitations_count` = COALESCE(`invitations_count`, 0) + 1 WHERE `admin_users`.`id` = 1*

1条回答
可以哭但决不认输i
2楼-- · 2019-08-28 06:09

This issue has happened after updating the gem devise_invitable to version 1.3.3

To fix it just create a migration

rails g migration AddInvitationsCountToAdminUsers invitations_count:integer

That should add invitations_count field to the table admin_users

For others who has got the same problem but in another table. Here is a migration for a general table users

rails g migration AddInvitationsCountToUsers invitations_count:integer 

Such issue could be caught by rspec

it 'user can be invited with passing current_user' do
  current_user_attr = {email: 'user1@example.com', password: 'xxxxxx', password_confirmation: 'xxxxxx', ... add your fields }
  user_attr = {email: 'user2@example.com', password: 'xxxxxx', password_confirmation: 'xxxxxx', ... add your fields }
  current_user = User.create!(current_user_attr)
  user = User.create!(user_attr)
  user.invite!(current_user).class.should eq(Mail::Message)
end
查看更多
登录 后发表回答