PostsController #new中的SyntaxError我不认为是语法错误

时间:2018-01-23 05:04:51

标签: ruby-on-rails controller syntax-error

我正在使用Rub on rails开发博客。问题出在我的postsController#new中。它告诉我一个sytax错误,我不认为它是一个语法错误。 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 %>

但是当我在删除那条线时,它继续下一行,依此类推。

这是我的控制者:

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

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

2 个答案:

答案 0 :(得分:1)

试试这个:

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

答案 1 :(得分:0)

使用此代码:

body {
background-color:#333;
}

#box {
z-index:2;
width:700px;
height:200px;
border:3px solid #e7f26d;
position:relative;
text-align:center;
color:#000;
}

#box * {
z-index:2;
}

#box::before {
content:"";
z-index:1;
position:absolute;
top:0;bottom:0;left:0;right:0;
background-image:url('https://www.picpng.com/image/view/110525');
background-image:no-repeat;
background-position:center;
-webkit-animation:grow-rotate 4s linear normal;
}

@-webkit-keyframes grow-rotate { 
0% {transform: rotate(320deg) scale(0);}
100% {transform: rotate(360deg) scale(0.2);} 
}