Names in Posts#index显示/home/alexandr/Huntjob/app/views/posts/index.html.haml第4行出现的位置:
#的未定义局部变量或方法'haml_temp'你的意思是? haml_tagenter image description here
发生错误的代码
- @posts.each do |post|
=link_to (image_tag post.image.url(:small))
%h2= link_to post.title, post
= link_to "Add New Inspiration", new_post_path
Post 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")
end
def show
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
HAML是缩进敏感的。从屏幕截图中,我看到问题出在缩进中。
应该起作用: