我可以引入公司关联的事件数据,但无法引入与该事件关联的照片。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