I can bring in Companies linked Events data, but am not able to bring in the photo that is linked to that event.
Company has_many Events & Event has_many Photos
Currently my code in Company/Show looks like
<% 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 %>
Company Controller
def show
@company = Company.find(params[:id])
end
I am using Paperclip for my Images. Any help would be much appreciated.
Code form Event Model (Keep in mind I am trying to access from Company)
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