Reputation: 1175
I have 2 tables, one of venuetypes and one of mapicons. A venuetype belongs to a mapicon.
Each mapicon has a name and an image uploaded with paperclip.
When I view a venuetype record I have the associated mapicon displayed using this bit of code:
<%= image_tag @venuetype.mapicon.mapicon.url(:mapicon) %>
I have another table of venues where each venue belongs to a venuetype.
However when I view a venue record on the index page the mapicon doesn't display the image, it just shows as a blank div with the properties set in the css class.
This is the code im using to atempt to display the mapicon:
<div id="venue_map_icon_<%= venue.id %>" style="position:absolute;" <%= image_tag (venue.venuetype.mapicon.mapicon.url(:mapicon)), :class => "mapicon" %></div>
I hope my question makes sense, I wil try clarify if needed, thanks for any help its much appreciated!
edit
mapicon model
class Mapicon < ActiveRecord::Base
has_many :venuetypes
has_attached_file :mapicon,
:styles => {
:mapicon => "20x20" }
end
venuetype model
class Venuetype < ActiveRecord::Base
has_many :venues
belongs_to :mapicon
has_attached_file :icon,
:styles => {
:thumb=> "100x100>",
:small => "150x150>",
:medium => "300x300>",
:large => "400x400>" },
:default_url => '/images/noimage.png'
end
venue model
class Venue < ActiveRecord::Base
attr_accessible :name, :addressline1, :addressline2, :addressline3, :addressline4, :postcode, :phonenumber, :about, :icontoppx, :iconleftpx, :area_id, :venuetype_id, :lat, :long, :venuephotos_attributes
belongs_to :area
belongs_to :venuetype
has_many :reviews
has_many :venuephotos
accepts_nested_attributes_for :venuephotos, :allow_destroy => true
scope :with_type, lambda { |types|
types.present? ? where(:venuetype_id => types) : scoped }
scope :with_area, lambda { |areas|
areas.present? ? where(:area_id => areas) : scoped }
def to_param
"#{id}-#{name.gsub(/\W/, '-').downcase}"
end
end
Upvotes: 2
Views: 266
Reputation: 2805
GAH! I think I see it, if this is it we'll be kicking ourselves...
Your view tags are jumbled:
<div id="venue_map_icon_<%= venue.id %>" style="position:absolute;" <%= image_tag (venue.venuetype.mapicon.mapicon.url(:mapicon)), :class => "mapicon" %></div>
It's missing a closing ">" on the first div, and also the closing parentheses on the image_tag call is misplaced. It should be after "mapicon", as such:
<div id="venue_map_icon_<%= venue.id %>" style="position:absolute;">
<%= image_tag(venue.venuetype.mapicon.mapicon.url(:mapicon), :class => "mapicon") %>
</div>
Unless "mapicon" class is supposed to be on the div, in which case it would look like this:
<div id="venue_map_icon_<%= venue.id %>" style="position:absolute;" class="mapicon">
<%= image_tag(venue.venuetype.mapicon.mapicon.url(:mapicon)) %>
</div>
I think the single-line horizontal scroll display messed with my head and prevented me from seeing it. When I saw your workaround in paragraph form, it jumped right out at me.
Hope this is it. :)
Upvotes: 1