我可以引入公司關聯的事件數據,但無法引入與該事件關聯的照片。Rails Showing Has_Many Linked Objects Photos
公司的has_many活動& 事件的has_many照片
目前我在公司/顯示的代碼看起來像
<% if @company.events.exists? then %>
<% @company.events.offset(1).each do |event| %>
<li><h3><%= link_to "#{event.name}", {:controller => "events", :action => "show", :id => event.id}, :rel => "external" %></h3>
<p>By <%= event.artist %></p></li>
<%= image_tag event.photo.photo.url(:large) %>
<% end %>
<% else %>
<p> There are no current events attached</p>
<% end %>
公司負責
def show
@company = Company.find(params[:id])
end
我使用回形針的我的圖片。任何幫助將非常感激。
代碼形式事件模型(請記住我試圖從公司獲得)
class Event < ActiveRecord::Base
attr_accessible :name, :description, :artist, :starttime, :startdate, :finishdate, :company_id, :photos_attributes
belongs_to :company
has_many :photos
accepts_nested_attributes_for :photos, :allow_destroy => true, :reject_if => lambda { |a| a[:photo].blank? }
accepts_nested_attributes_for :company
end
目前,我有 @event = Event.where(:COMPANY_ID =>:ID,:爲了=> 'DESC') – 2012-04-04 03:54:02
目前,我有我的CONTROLER 「@event = Event.where (:COMPANY_ID =>(PARAMS [:ID]))」 當我打電話這在我的顯示動作 '<%= IMAGE_TAG @event%>' 結果是空白圖像,這表明在HTML '' – 2012-04-04 04:01:20
您尚未正確設置回形針與您r事件模型。粘貼該關聯的代碼並編輯您的問題。 – 2012-04-04 05:26:51