gpt4 book ai didi

ruby-on-rails - 我认为不是PostsController#new中的SyntaxError语法错误

转载 作者:行者123 更新时间:2023-12-03 08:27:11 24 4
gpt4 key购买 nike

我正在用Rub on Rails开发博客。问题出在我的postsController#new中。它告诉我一个语法错误,我认为它不是语法错误。
enter image description here

这应该是语法错误
注意:这是分手

        <%= form_for @post, html: { multipart: true } do |f| %>
<%= render 'shared/error_messages' %>
<%= f.collection_select(:category_id, Category.all, :id, :name, {prompt: “Choose a category” }) %><br> <-Ruby says this is my error.
<%= f.label :title %><br>
<%= f.text_field :title %><br>
<%= f.label :content %><br>
<%= f.text_area :content %><br>
<%= f.label :image %><br>
<%= f.file_field :image %><br>

<%= f.submit %>
<% end %>

但是,当我调试该行的调试时,它会继续前进到下一行,依此类推。

这是我的 Controller :
class PostsController < ApplicationController
before_action :find_post, only: [:show, :edit, :update, :destroy]
before_action :authenticate_admin!
def index
@posts = Post.all
end

def show
end

def new
@post = Post.new
end

def create
@post = Post.new(post_params)
if @post.save
flash[:success] = "El post se publicó exitosament"
redirect_to posts_path
else
render 'new'
end
end

def edit

end

def update
if @post.update(post_params)
flash[:success] = "Post actualizado correctamente"
redirect_to @post
else
render 'edit'
end
end

def destroy
@post.destroy
flash[:success] = "Post borrado exitosamente"
redirect_to posts_path
end

private
def post_params
params.require(:post).permit(:title, :content, :category_id, :image)
end

def find_post
@post = Posts.find(params[:id])
end
end

还有我的帖子模型
class Post < ApplicationRecord
belongs_to :category
validates :title, :content, :category_id, presence: true
has_many :line_items, inverse_of: :order
mount_uploader :image, ImageUploader
end

感谢您的帮助,我不认为这是语法错误,但希望您能帮助我找到此错误。
感谢开发人员!

最佳答案

尝试这个:

<%= f.collection_select :category_id, Category.all, :id, :name, prompt: 'Choose a category' %>

关于ruby-on-rails - 我认为不是PostsController#new中的SyntaxError语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48394572/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com