回形针显示图像网址是undefine

时间:2015-06-23 06:37:58

标签: ruby-on-rails

我想在每个循环中显示图像,图像由paperclip gem上传。真正的道路是

/system/users/images/000/000/035/original/lovecupcake.jpg

当我使用它时,这工作正常

rails code <%= image_tag @user.image.url(:medium) %>  

output <img alt="Lovecupcake" src="/system/users/images/000/000/035/original/lovecupcake.jpg">

它显示我的图像但是当我应用循环

<% @result.each do |r| %>
            <tr>

                <td> 
                    <% image = r['image_file_name'] %>
                    <%=image_tag r['id'].image.url %>

                    </td>
                </td>

            </tr>
        <% end %>

检查结果后

#<ActiveRecord::Relation [#<User id: 35, email: "jaskaransingh@zapbuild.com", encrypted_password: "899999", reset_password_token: "989899...", reset_password_sent_at: "2015-06-22 11:30:27", remember_created_at: nil, sign_in_count: 29, current_sign_in_at: "2015-06-23 04:09:31", last_sign_in_at: "2015-06-22 11:50:16", current_sign_in_ip: #<IPAddr: IPv4:127.0.0.1/255.255.255.255>, last_sign_in_ip: #<IPAddr: IPv4:127.0.0.1/255.255.255.255>, created_at: "2015-06-10 10:06:51", updated_at: "2015-06-23 05:13:31", confirmation_token: "c8d8f972b71aaddeded92c763176ddb153414a44d3383aae74...", confirmed_at: "2015-06-10 10:21:24", confirmation_sent_at: "2015-06-10 10:20:53", unconfirmed_email: nil, first_name: "jaskaran", last_name: "singh", date_of_birth: "1987-11-26", sex: 2, phone: "(904) 457-4587", address: "Calumet Avenue – U.S. 41 North", price: 90, profession: "hiw", city_id: 8393, state_id: 136, country_id: 254, zip_code: 140901, image_file_name: "lovecupcake.jpg", image_content_type: "image/jpeg", image_file_size: 307058, latitude: 41.6075171, longitude: -87.5089279, sponser_code: "123456", bio: "dasf", eye_color: "Black", hair_color: "Black", weight: 45.45, is_active: true, height: 4.5, butt_size: "small", breast_size: "">]>

它没有显示我的图像

我错了

1 个答案:

答案 0 :(得分:1)

所以你的@result是一组用户。只需致电<%= r.image.url(:medium) %>