2
페이지 (adtype)의 내용을 정의하는 두 개의 탐색 막대 (배치 & ad)가 있습니다. 첫 번째 탐색 모음 인 게재 위치는 항상 맨 위에 표시됩니다. 두 번째 탐색 바 (ad)는 게재 위치의 맨 위에 선택된 속성을 기반으로 페이지의 왼쪽에 렌더링됩니다. 모델 배치 & 모델 광고에는 많은 관계가 있습니다. 상단 네비게이션 바에서 어떤 속성이 선택되었는지에 따라 html로 두 번째 네비게이션 광고를 렌더링하려면 어떻게해야합니까?랜더링 연관 데이터 (has_many, : through) - 레일
두 탐색 모델은 다음과 같습니다 여기
class Adtype < ActiveRecord::Base
attr_accessible :adtype_screenshot, :location, :placement_screemshot, :specs
belongs_to :placements
belongs_to :ads
end
내 스키마 데이터베이스입니다 : 여기
class Placement < ActiveRecord::Base
attr_accessible :placementname
has_many :adtypes, :foreign_key => "placement_id"
has_many :ads, :through => :adtypes
end
class Ad < ActiveRecord::Base
attr_accessible :adname
has_many :adtypes, :foreign_key => "ad_id"
has_many :placements, :through => :adtypes
end
이 속성은 탐색 모음에서 선택한 무엇에 따라 내용, adType을위한 모델이며, :
:
여기
ActiveRecord::Schema.define(:version => 20121127052112) do
create_table "ads", :force => true do |t|
t.string "adname"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "adtypes", :force => true do |t|
t.integer "placement_id"
t.integer "ad_id"
t.string "location"
t.string "placement_screenshot"
t.string "adtype_screenshot"
t.string "specs"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "placements", :force => true do |t|
t.string "placementname"
t.datetime "created_at"
t.datetime "updated_at"
end
end
내 routes.rb 파일입니다
내 상단 네비게이션 (_navigation.html.erb)을 렌더링 및 게재 위치 ID (: // localhost를 3000/게재 위치에/2 HTTP)로 끝나는 새 URL로 각각의 속성을 연결하고 방법은 다음과resources :placements do
resources :ads do
resources :adtypes do
end
end
end
입니다
<% Placement.all.each do |placement| %>
<li ><%= link_to placement.placementname, placement_path(placement.id) %> </li>
<%end%>
_ad_ 탐색 표시 줄을 렌더링해야하는 제어기 조치 또는 조치는 무엇입니까? 단지'placements # show'입니까 아니면 전체 사이트에서 표준 템플릿으로 지정되어 있습니까? – Geoff
전체 사이트에 있어야합니다. 방금 해결책을 찾았지만. 먼저 belongs_to : 게재 위치 belongs_to : ads 광고를보기 위해 광고를 보았습니다. . 각각 | 광고 | %>
죄송합니다, 나는 그것을 잡은해야으로보고합니다. 답변을 작성하여 수락하는 것이 좋습니다. – Geoff