Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.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 Post model缺少';图像文件名';_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails Post model缺少';图像文件名';

Ruby on rails Post model缺少';图像文件名';,ruby-on-rails,ruby,Ruby On Rails,Ruby,我刚开始用RubyonRails做一个示例网页。 当我试图从表单发布图像时,收到一个错误“发布模型缺少‘图像文件名称’所需的属性访问器” 我的代码是 routes.rb Rails.application.routes.draw do resources :posts root 'posts#index' end posts_controll.rb class PostsController < ApplicationController def index e

我刚开始用RubyonRails做一个示例网页。 当我试图从表单发布图像时,收到一个错误“发布模型缺少‘图像文件名称’所需的属性访问器”

我的代码是 routes.rb

Rails.application.routes.draw do
resources :posts 
root 'posts#index'  
end
posts_controll.rb

class PostsController < ApplicationController
    def index  
    end
    def new  
        @post = Post.new
    end
    def create
        @post = Post.create(post_params)
        redirect_to posts_path  
    end
    private

    def post_params  
        params.require(:post).permit(:image, :caption)
    end
end
class PostsController
newhtml.erb

<%= simple_form_for @post do |f| %>
  <%= f.input :image %>
  <%= f.input :caption %>
  <%= f.button :submit %>
<% end %>

post.rb

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
class Post“640x”}
验证\u附件\u内容\u类型:图像,:内容\u类型=>/\Aimage\/.\Z/
结束
我不明白这里的错误。我想我做得很好


伙计们,请帮帮我。

错误很清楚,但您的代码不清楚。“image\u file\u name”这是从哪里来的?您的images表根本没有名为image\u file\u name的字段。如果它有这样一个字段,那么activerecord将为您创建attr_访问器。您应该考虑通过迁移添加它。错误是清楚的,但是您的代码不是。“image\u file\u name”这是从哪里来的?您的images表根本没有名为image\u file\u name的字段。如果它有这样一个字段,那么activerecord将为您创建attr_访问器。您应该考虑通过迁移添加它。