Reputation: 35
I'm converting my app from paperclip to carrierwave based on the documentation on carrierwave's github:https://github.com/carrierwaveuploader/carrierwave and advice from this blog:http://bessey.io/blog/2013/04/07/migrating-from-paperclip-to-carrierwave/
However I'm getting a undefined method error for `exists?' in Articles#show.
Here is my _form.html.erb code
<%= form_for(@article, html: {multipart: true}) do |f| %>
.
.
.
<p>
<% if @article.image.exists? %>
<%= image_tag @article.image.url %><br />
<% end %>
<%= f.label :image, "Attach a New Image" %><br />
<%= f.file_field :image %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
Here is Articles#show
def show
@article = Article.find(params[:id])
end
The Articles Model
class Article < ActiveRecord::Base
mount_uploader :image, ImageUploader, :mount_on => :image
default_scope -> { order('created_at DESC') }
has_many :comments
has_many :taggings
has_many :tags, through: :taggings
# has_attached_file :image
# validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/gif", "image/png"]
def total_pages
@articles = Article.all
end
def tag_list
self.tags.collect do |tag|
tag.name
end.join(", ")
end
def tag_list=(tags_string)
tag_names = tags_string.split(",").collect{|s| s.strip.downcase}.uniq
new_or_found_tags = tag_names.collect { |name| Tag.find_or_create_by(name: name) }
self.tags = new_or_found_tags
end
end
Let me know if you need to see anything else. I'm still learning rails and I'm not sure where I need to be looking to debug this particular error.
Upvotes: 1
Views: 444
Reputation: 1149
To check the presence of the image you can just use
<% if @article.image_url %>
<%= image_tag @article.image.url %><br />
<% end %>
For more information about setting up carrier wave in your app check this episode of railscasts
Upvotes: 1