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

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

Closed
iamdriz opened this issue Aug 12, 2020 · 3 comments
Closed

Comments

@iamdriz
Copy link

iamdriz commented Aug 12, 2020

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

@iamdriz iamdriz changed the title can't write unknown attribute sash_id when using current_user.points can't write unknown attribute sash_id when calling points method on user Aug 12, 2020
@iamdriz
Copy link
Author

iamdriz commented Aug 13, 2020

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.

@iamdriz iamdriz closed this as completed Aug 13, 2020
@tute
Copy link
Member

tute commented Aug 13, 2020

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

@tute
Copy link
Member

tute commented Aug 13, 2020

(Or whoever gets before me!)

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

No branches or pull requests

2 participants