Ruby를 처음 보았을 때 언어 이해에 도움이되는 Ruby를 처음 접했고 실력을 연마 할 샘플 애플리케이션을 코딩했습니다.연관 문법 ruby on rails
나는 제품 & 미디어 사이에 많은 관계가 있음을 설정하려고 시도했습니다. 나는 "가지고 m가 문제를 해결하는 방법을 잘하기 때문에 복수 형태의 매체입니다,하지만 도전을 의심
class CreateMedia < ActiveRecord::Migration
def change
create_table :media do |t|
t.string :type
t.string :alt
t.boolean :is_primary
t.string :url_tiny
t.string :url_small
t.string :url_regular
t.string :url_large
t.string :title
t.timestamps
end
end
end
class Media < ActiveRecord::Base
attr_accessible :alt, :is_primary, :title, :type, :url_large, :url_regular, :url_small, :url_tiny
belongs_to :product
end
class Product < ActiveRecord::Base
attr_accessible :assoc_product,:product_id, :merch_associations, :aux_description, :buyable, :long_description, :name, :on_special, :part_number, :release_date, :short_description, :withdraw_date, :occasion
has_and_belongs_to_many :categories
has_many :merch_associations
has_many :assoc_products, :through => :merch_associations
has_many :media
...
나는이 (노트 dress_media이 채워진 미디어 객체 배열)를 실행하면 :.
products[i].media << dress_media[m]
나는 오류 콘솔이 얻을 :.
uninitialized constant Product::Medium
내가 DB에 보니 테이블이 실제로 미디어가 아닌 매체라고 그래서 나는 복수를 잘 했어야 생각 (이 코드가 생성 된? 일부터 전자 레일 제너레이터)
레일즈에 익숙하지 않은 사람이 제품 & 미디어 사이에이 하나를 만들 수있는 올바른 방향으로 나를 가리킬 수 있다면 그렇게 좋을까요?
감사합니다. 아마 나는 Ruby on Rails보다 영어를 더 공부해야만한다 :) Medium으로 이름을 바꾸면 해결되었다. 건배. –