I'm developing an online store application with rails.And in that i have included a paperclip gem to store images of the items.The image gets successfully stored to the database but when i'm trying to retrieve the image with it's show view i am getting an error saying that
> undefined method `image?' for #<Item:0x007f805b7a9d50>
Extracted source (around line #19):
<div>
<% if @item.image? %>
<% image_tag @item.image.url%>
<br>
<%end%>
</div><br>
This is my code in the view to submit the image
`<div>
<%=f.label :image %>
<%=f.file_field :image %><br><br>
</div>
<div>`
This is the migration file for the image storing on the table
`class AddImageToItems < ActiveRecord::Migration[5.0]
def self.up
add_column :items, :image_file_name, :string
add_column :items, :image_content_type, :string
add_column :items, :image_file_size, :integer
add_column :items, :image_updated_at, :datetime
end
def self.down
remove_column :items, :image_file_name
remove_column :items, :image_content_type
remove_column :items, :image_file_size
remove_column :items, :image_updated_at
end
end
`
This is the code for the show view
`<div class="well">
<h3> Item : <%= @item.title %> </h3>
</div>
<div>
<i>Quantity : </i><%= @item.qty %>
</div>
<div>
<i>Price : RS </i><%= @item.price %>
</div><br>
<div>
<% if @item.image? %>
<% image_tag @item.image.url%>
<br>
<%end%>
</div>`
This is my show method on the items controller
def show @item =Item.find(params[:id]) end
Please help me to Solve this issue...
Aucun commentaire:
Enregistrer un commentaire