アプリケーションで新たな問題が発生しました。
私はこのように多対多の関係を作ろうとします: http://guides.rubyonrails.org/association_basics.html#the-has_and_belongs_to_many-association ここでは、has_and_belongs_to_many を使用して 2 つのテーブルを「接続」します: User & Pins
しかし、ユーザーのピン数を数えようとすると、このエラーが発生します。
Showing /app/views/shared/_users_pins.html.erb where line #4 raised:
SQLite3::SQLException: no such column: pins_users.user_id: SELECT COUNT(*) FROM "pins" INNER JOIN "pins_users" ON "pins"."id" = "pins_users"."pins_id" WHERE "pins_users"."user_id" = 102
line 4 : <%= @user.pinss.count %>
(ピンの代わりにピンを使用する必要があります。そうしないと、レールはピンの代わりにピンクラスを検索しますが、それはとても汚いです:'( )
ここに私のモデルがあります:
class Pins < ActiveRecord::Base
attr_accessible :describe, :title, :url_img
has_and_belongs_to_many :users
end
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation, :team_id
has_and_belongs_to_many :pinss
end
ありがとう!=)
一番。