相关记录中的图像不会显示在索引页上
我有两张桌子,一张是场地类型,一张是地图图标。场地类型属于地图图标。
每个地图图标都有一个名称和一张用回形针上传的图像。
当我查看场地类型记录时,我使用这段代码显示关联的地图图标:
<%= image_tag @venuetype.mapicon.mapicon.url(:mapicon) %>
我有另一个场地表,其中每个场地都属于一个场地类型。
但是,当我在索引页面上查看场地记录时,mapicon 不会显示图像,它只是显示为一个空白 div,其属性在 css 类中设置。
这是我用来尝试显示地图图标的代码:
<div id="venue_map_icon_<%= venue.id %>" style="position:absolute;" <%= image_tag (venue.venuetype.mapicon.mapicon.url(:mapicon)), :class => "mapicon" %></div>
我希望我的问题有意义,如果需要,我会尝试澄清,感谢您的任何帮助,非常感谢!
编辑
mapicon模型
class Mapicon < ActiveRecord::Base
has_many :venuetypes
has_attached_file :mapicon,
:styles => {
:mapicon => "20x20" }
end
venuetype模型
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
场地模型
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘎啊!我想我看到了,如果是这样,我们会踢自己的...
您的视图标签很混乱:
<
div id="venue_map_icon_<%=venue.id %>"样式=“位置:绝对;” <%= image_tag (venue.venuetype.mapicon.mapicon.url(:mapicon)), :class =>; "mapicon" %>
它缺少结束符“>”在第一个 div 上,并且 image_tag 调用上的右括号也放错了位置。它应该在“mapicon”之后,如下所示:
除非“mapicon”类应该在div上,在这种情况下它看起来像这样:
我认为单行水平滚动显示弄乱了我的头并阻止了我看到它。当我看到你的段落形式的解决方法时,它立刻引起了我的注意。
希望就是这样。 :)
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:
Unless "mapicon" class is supposed to be on the div, in which case it would look like this:
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. :)