0

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
4

1 回答 1

0

你错过了

has_attached_file :photo, :styles => {...}

参与你的Event模型。

请参阅此回形针的简单示例,如果您仍然遇到任何问题,请在此处发布。

于 2012-04-04T09:06:45.753 回答