Ruby on rails Rails的控制器设置有许多贯穿关系
我有一个类似的问题。我是一个新手,已经阅读了几个小时关于如何得到这个答案,但还没有得到答案,非常感谢您的帮助!我已经按照Kikito的答案设置了以下模型:用户、照片、位置、照片和关系。我的路由文件包含:Ruby on rails Rails的控制器设置有许多贯穿关系,ruby-on-rails,controller,has-many-through,Ruby On Rails,Controller,Has Many Through,我有一个类似的问题。我是一个新手,已经阅读了几个小时关于如何得到这个答案,但还没有得到答案,非常感谢您的帮助!我已经按照Kikito的答案设置了以下模型:用户、照片、位置、照片和关系。我的路由文件包含: resources :users resources :locations do resources :photos end resources :photo_relationships 我能够将照片保存到应用程序中的正确位置,但无法通过照片关系模型将多个用户(特别是照片的创建者)分配到
resources :users
resources :locations do
resources :photos
end
resources :photo_relationships
我能够将照片保存到应用程序中的正确位置,但无法通过照片关系模型将多个用户(特别是照片的创建者)分配到照片
class CreatePhotoRelationshipsTable < ActiveRecord::Migration
def change
create_table :photo_relationships do |t|
t.integer :photo_id
t.integer :user_id
t.integer :role_id
t.timestamps
end
照片/关系控制器
def create
@location = Location.find(params[:location_id])
@photo = @location.photos.new(params[:photo])
@photo.create_photo_relationship(@photo, current_user, 0)
if @photo.save
flash[:notice] = "Successfully added your photo"
redirect_to [@mountain, @photo]
else
render :action => 'new'
end
end
def create
@relationship = photo_relationships.new(params[:photo][:location])
@photo.create_photo_relationship()
end
我当前的错误是未定义的方法“photo_relationship”。非常感谢任何人能够提供的帮助或指导。课程名称为
PhotoRelationship
而不是photo\u relations
控制器行应为:
@relationship = PhotoRelationship.new(params[:photo][:mountain])
谢谢Max的回复。我关掉了这个,现在有一个稍微不同的错误:预期的app/models/photo_relationship.rb定义照片关系。(我还切换了创建照片关系代码来构建。)
app/models/photo_relationship.rb的类声明是什么?它应该是类光关系
。