Ruby version 2.2.4 Rails version 5.0.0.1 Carrierwave
Hello people
I am a totally beginner in RoR and after long hours I finally uploaded an picture from my android app to ruby on rails. I have the code from a tutorial which provides the upload function. However the function how you can see the picture is missed. How can I implement this in ruby on rails? I want to see the pictures in a table
Here is what I have so far
And here is the code: views/items/inde.html.erb
h1>Rails-API-Fileupload-tutorial-Cariierwave-Single</h1>
<h2>Listing documents</h2>
<table>
<thead>
<tr>
<th>Filename</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @items.each do |item| %>
<tr>
<td><%= item.id %></td>
<td><%= item%></td>
</tr>
<% end %>
</tbody>
</table>
<br>
routes.rb
Rails.application.routes.draw do
resources :items, :pictues
root to: redirect('/items')
post to: 'items'
end
UPDATE: Hello People, thanks for your fast help. When I use <%= image_tag item.picture %>
I get this
Are there some other ideas?
UPDATE: I think I cannot see the pictures because I have a routing problem. When I right click on a picture and want to open in new browser I get
ActionController::RoutingError: No route matches [GET]
What can I do to fix this?
UPDATE: My Uploadfolder is outside of Ruby and Rails folder. Should it be in the public ordner instead?
<td><%= item%></td>
should be something like :
<td><%= image_tag item.picture %></td>
要显示图像,请使用image_tag
。
<%= image_tag item.picture_url %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.