开发者

Help getting names in view for attachments in Rails

开发者 https://www.devze.com 2023-03-21 05:54 出处:网络
I want to display attachments in my asset view and I have this in my view: <% if @asset.attachments.size > 0 %开发者_如何学C>

I want to display attachments in my asset view and I have this in my view:

<% if @asset.attachments.size > 0 %开发者_如何学C>
    <% @asset.attachments.each_with_index do |attachment| %>
    <%= image_tag attachment.to_s %>  
    <%end%>
    <%end%>

and I have this in my controller (just the basic):

 def show
@asset = Asset.find(params[:id])

respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @asset }
end

end

When I want it to show the name (which is in the attachment field of the attachments table). But the code only gives me

 #<attachment #<attachment

as output in the view. What am I missing?


Calling attachment here is just referencing the class it looks like. Is there a name field for attachment so you could call something like <%= image_tag attachment.name %>?

0

精彩评论

暂无评论...
验证码 换一张
取 消