私はレールに慣れていないので、モデルの関連付けについて少し混乱しています。ここでは、何をする必要があるかについて簡単に説明します。、 、 、およびというUser
モデルがあります。has_many project
Project
has_many upload
Upload
belongs_to project
Project
belongs_to user
これまでのところ、ユーザーはプロジェクトにアクセスでき、そのプロジェクトからアップロードにアクセスできます。つまり、どのユーザーもすべてのユーザーのプロジェクトとアップロードにアクセスできます。URL localhost:3000/projects/9/uploads/57 を変更して、正しいユーザー (プロジェクトとアップロードを作成したユーザー) のみがプロジェクトとアップロードにアクセスできるようにする必要があります。
schema.rb
create_table "projects", force: true do |t|
t.string "name"
t.string "comment"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "uploads", force: true do |t|
t.integer "project_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "edl_file_name"
t.string "edl_content_type"
t.integer "edl_file_size"
t.datetime "edl_updated_at"
end
create_table "users", force: true do |t|
t.string "name"
t.string "email"
t.datetime "created_at"
t.datetime "updated_at"
t.string "password_digest"
t.string "remember_token"
end
ユーザーモデル
has_many :project
has_many :upload, :through => project
プロジェクトモデル
belongs_to :user
has_many :upload, :dependent => :destroy
モデルのアップロード
belongs_to :project
has_one :user, :through => :project
ルート.rb
resources :users
resources :projects do
resources :uploads do
end
end
もしかして関係?どうやってそれをしますか?