비디오, 주제 및 사용자를 프로필에 게시 할 수 있도록 has_many_polymorphs 플러그인을 사용하고 있습니다. 따라서 프로필에는 비디오, 주제 및 사용자가 될 수있는 많은 "showable_objects"가 있습니다. 또한 "showable_object"를 생성 한 사용자도이 객체와 연관됩니다. 이미 모델 연결을 설정했습니다 (아래).has_many_polymorphs 및 오류에 대한 CRUD 컨트롤러 작업을 설정하는 방법
showable_object를 만들려는 방식은 사용자가 리소스의 표시 페이지에서 자동 완성 필드에서 다른 사용자를 선택하는 것입니다. 그러면 해당 자원이 선택된 사용자의 프로파일과 연관됩니다.
제 질문은 showable_objects 컨트롤러를 어떻게 설정해야합니까? 또한 AJAX를 통해 전송되기를 원한다면 AJAX jQuery 요청은 어떻게 생겼을까요?
UPDATE :
class CreateShowableObjects < ActiveRecord::Migration
def self.up
create_table :showable_objects do |t|
t.references :showable_object, :polymorphic => true
t.references :profile
t.references :user
t.timestamps
end
end
def self.down
drop_table :showable_objects
end
end
나는 또한이 협회에서이 오류를 (받고 있어요 그런데이 내 ShowableObject 마이그레이션
class ShowableObject < ActiveRecord::Base
belongs_to :showable_object, :polymorphic => true
belongs_to :user
belongs_to :profile
end
class Profile < ActiveRecord::Base
has_many_polymorphs :showable_objects, :from => [:videos, :users, :topics, :video_votes],
:dependent => :destroy
end
class User < ActiveRecord::Base
has_many_polymorphs :showable_objects, :from => [:videos, :users, :topics, :video_votes],
:dependent => :destroy
end
입니다 : 여기
내 모델 협회입니다 그래서 이것은 실제로 두 부분 질문입니다 : P) :ActiveRecord::Associations::PolymorphicError in Videos#index
Showing /rubyprograms/dreamstill/app/views/videos/_video.html.erb where line #24 raised:
Could not find a valid class for :showable_objects_users (tried ShowableObjectsUser). If it's namespaced, be sure to specify it as :"module/showable_objects_users" instead.
이 줄은 <% if video.owned_by? current_user %>
이며, 사용자 모델에서는 has_many_polymorphs
호출과 관련이 있습니다.