ruby on rails - Getting NameError while linking Dragonfly gem to index.html.erb -
i have linked dragonfly gem project , uploads images creating posts via _form, when i'm trying add these created posts index.html.erb alltogether uploaded using dragonfly-gem images, shows me nameerror. have made operation in few projects, in project have no idea error comes from. here case:
nameerror in posts#index undefined local variable or method `posts' #<#:0x66f9d20>
extracted source (around line #5):
5. <%= link_to image_tag(posts.image.thumb('64x64!').url) %>
posts controller:
class postscontroller < applicationcontroller before_action :find_post, only: [:show, :edit, :update, :destroy] before_action :authenticate_user!, except: [:index, :show] def index @posts = post.all.order("created_at desc") end def show @post = post.find(params[:id]) end def new @post = current_user.posts.build end def create @post = current_user.posts.build(post_params) if @post.save redirect_to @post else render 'new' end end def edit end def update if @post.update(post_params) redirect_to @post else render 'edit' end end def destroy @post.destroy redirect_to root_path end private def find_post @post = post.find(params[:id]) end def post_params params.require(:post).permit(:title, :link, :description, :image) end end
index.html.erb:
<% @posts.each |post| %> <h2><%= link_to post.title, post %></h2> <% end %> <%= link_to image_tag(posts.image.thumb('64x64!').url) %>
post model:
class post < activerecord::base belongs_to :user dragonfly_accessor :image end
user model:
class user < activerecord::base # include default devise modules. others available are: # :confirmable, :lockable, :timeoutable , :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_many :posts end
show.html.erb:
<h1><%= @post.title %></h1> <%= image_tag @post.image.thumb('300x300#').url if @post.image_stored? %> <p><%= @post.link %></p> <p><%= @post.description %></p> <p><%= @post.user.name %></p>
try changing index.html.erb
this
<% @posts.each |post| %> <h2><%= link_to post.title, post %></h2> <%= link_to image_tag(post.image.thumb('64x64!').url) %> <% end %>
Comments
Post a Comment