Reputation: 73
I was looking for a way to just upload photos to a database and displaying photos on a page. I am trying carrierwave. It uploads the photo correctly, I think, but when it goes to display the image all it does is give the location (url) of it.
Here is the uploader
class Image < ActiveRecord::Base
attr_accessible :image, :title
mount_uploader :image, ImageUploader
end
Here is the form used to upload the file
<%= form_for @image, :html => {:multipart => true} do |f| %>
<% if @image.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@image.errors.count, "error") %> prohibited this image from being saved:</h2>
<ul>
<% @image.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :image %><br />
<%= f.file_field :image %>
</div>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
This is to display the image
<p id="notice"><%= notice %></p>
<p>
<b>Image:</b>
<%= @image.image_url.to_s %>
</p>
<p>
<b>Title:</b>
<%= @image.title %>
</p>
<%= link_to 'Back', images_path %>
This is what prints out:
Image: /uploads/image/image/2/946612_524939910875157_1455921715_n.jpg
Title: poster
Upvotes: 4
Views: 4868
Reputation: 3339
to display this image, try this.
<%= image_tag @image.image_url.to_s if @image.image_url.present? %>
Upvotes: 4