Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的方法'image';对于#<;邮政编码:0x007f6018a697b0>;_Ruby On Rails_Ruby_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 未定义的方法'image';对于#<;邮政编码:0x007f6018a697b0>;

Ruby on rails 未定义的方法'image';对于#<;邮政编码:0x007f6018a697b0>;,ruby-on-rails,ruby,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 4,我的项目中出现以下错误: 未定义的方法“image”# 这是我的模型post.rb class Post < ApplicationRecord class Post < ActiveRecord::Base validates :image, presence: true has_attached_file :image, styles: { :medium => "640x" } validates_attachme

我的项目中出现以下错误:

未定义的方法“image”#

这是我的模型post.rb

class Post < ApplicationRecord
    class Post < ActiveRecord::Base
        validates :image, presence: true

        has_attached_file :image, styles: { :medium => "640x" }
        validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
    end
end

class Post“640x”}
验证\u附件\u内容\u类型:图像,:内容\u类型=>/\Aimage\/.\Z/
结束
结束
这是我的控制器post_controller.rb

class PostsController < ApplicationController
    def index
    end

    def new
        @post = Post.new
    end
end
class PostsController
为什么要使用
类Post

新生成的应用程序具有
app/models/application\u record.rb
默认显示。新生成的模型必须继承自
ApplicationRecord
,但前提是它存在

因此,如果您使用的是
rails>=5
,请删除这个类
classpost
,或者如果您需要它,请删除第一个

见此参考

未定义的方法“image”

对于模型中找不到的
图像
属性,请确保已添加该属性,如果尚未添加该属性,请编写如下命令

rails g migration AddImageToPosts image:string

然后运行
rakedb:migrate

您可以添加与posts相关的
schema.rb
部分吗?
class Post
——这里发生了什么事??!!!这在我看来绝对是错的。
rails g migration AddImageToPosts image:string