merit-gem/merit

can't write unknown attribute `sash_id` when calling points method on user

iamdriz opened this issue · 3 comments

When calling: @user.points to show the points for the current user we get the error:

can't write unknown attribute `sash_id`

From the console I see the following:

Started GET "/forum/users/1" for ::1 at 2020-08-12 21:45:14 +0100
Processing by SimpleDiscussion::UsersController#show as HTML
  Parameters: {"id"=>"1"}
  User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/simple_discussion/users_controller.rb:7:in `show'
  Rendering simple_discussion/users/show.html.erb within layouts/simple_discussion
   (0.1ms)  SELECT COUNT(*) FROM "forum_threads" WHERE "forum_threads"."user_id" = ?  [["user_id", 1]]
  ↳ app/views/simple_discussion/users/show.html.erb:7
   (0.1ms)  SELECT COUNT(*) FROM "forum_posts" WHERE "forum_posts"."user_id" = ?  [["user_id", 1]]
  ↳ app/views/simple_discussion/users/show.html.erb:11
  User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ app/views/simple_discussion/users/show.html.erb:13
   (0.0ms)  begin transaction
  ↳ app/views/simple_discussion/users/show.html.erb:13
  Merit::Sash Create (0.3ms)  INSERT INTO "sashes" ("created_at", "updated_at") VALUES (?, ?)  [["created_at", "2020-08-12 20:45:14.271565"], ["updated_at", "2020-08-12 20:45:14.271565"]]
  ↳ app/views/simple_discussion/users/show.html.erb:13
  Merit::Score Create (0.1ms)  INSERT INTO "merit_scores" DEFAULT VALUES
  ↳ app/views/simple_discussion/users/show.html.erb:13
  Merit::Score Update (0.1ms)  UPDATE "merit_scores" SET "sash_id" = ? WHERE "merit_scores"."id" = ?  [["sash_id", 21], ["id", 21]]
  ↳ app/views/simple_discussion/users/show.html.erb:13
   (0.7ms)  commit transaction
  ↳ app/views/simple_discussion/users/show.html.erb:13
  Rendered simple_discussion/users/show.html.erb within layouts/simple_discussion (Duration: 12.7ms | Allocations: 9020)
Completed 500 Internal Server Error in 15ms (ActiveRecord: 1.7ms | Allocations: 10248)


  
ActionView::Template::Error (can't write unknown attribute `sash_id`):
    10: 
    11: <h2>Recent posts (<%= @user.forum_posts.count %>)</h2>
    12: 
    13: <%= @user.points %>

I've checked the database (SQLite in development) and all the tables look fine. Any ideas what's the cause?

Rails 6.0.3.2
Merit 4.0.0
Ruby 2.5.7

So this was caused because this migration wasn't generated:
https://github.com/merit-gem/merit/blob/master/lib/merit/generators/active_record/templates/add_merit_fields_to_model.erb

I manually created the migration and now it's working.

tute commented

Thanks for reporting. I need to fix it as part of #351

tute commented

(Or whoever gets before me!)