【发布时间】:2014-03-20 19:13:25
【问题描述】:
我在我的 rails 博客应用程序中尝试使用回形针上传时遇到此错误。 不确定当它说“MissingRequiredValidatorError”时它指的是什么 我认为通过更新 post_params 并给它 :image 就可以了,因为 create 和 update 都使用 post_params
Paperclip::Errors::MissingRequiredValidatorError in PostsController#create
Paperclip::Errors::MissingRequiredValidatorError
Extracted source (around line #30):
def create
@post = Post.new(post_params)
这是我的posts_controller.rb
def update
@post = Post.find(params[:id])
if @post.update(post_params)
redirect_to action: :show, id: @post.id
else
render 'edit'
end
end
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
if @post.save
redirect_to action: :show, id: @post.id
else
render 'new'
end
end
#...
private
def post_params
params.require(:post).permit(:title, :text, :image)
end
这是我的帖子助手
module PostsHelper
def post_params
params.require(:post).permit(:title, :body, :tag_list, :image)
end
end
如果我可以补充额外的材料来帮助你,请告诉我。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 paperclip