Ruby on rails haml的问题我研究RubyonRails时遇到了以下问题
Postsindex中的NameError 显示/home/alexandr/Huntjob/app/views/posts/index.html.haml,其中第4行出现: 未定义的局部变量或方法“haml_temp” 你是说?哈姆卢标签 发生错误的代码 岗位控制员Ruby on rails haml的问题我研究RubyonRails时遇到了以下问题,ruby-on-rails,ruby,haml,Ruby On Rails,Ruby,Haml,Postsindex中的NameError 显示/home/alexandr/Huntjob/app/views/posts/index.html.haml,其中第4行出现: 未定义的局部变量或方法“haml_temp” 你是说?哈姆卢标签 发生错误的代码 岗位控制员 HAML对压痕敏感。从截图中我看到问题出在缩进上 这应该是可行的: - @posts.each do |post| = link_to(image_tag post.image.url(:small)) %h2= lin
HAML对压痕敏感。从截图中我看到问题出在缩进上 这应该是可行的:
- @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
确保在第2行和第3行之前有两个空格。Ouuu-Yeee,谢谢。我意识到它是缩进的,但我尝试了各种选择,但是你的工人,非常感谢,显然我太笨了:
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
- @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