小编mes*_*jah的帖子

使用Rails 4的Paperclip :: Errors :: MissingRequiredValidatorError

当我尝试使用带有我的rails blogging app的paperclip上传时,我收到此错误.当它说"MissingRequiredValidatorError"时,不知道它是指什么我认为通过更新post_params并给它:image它会没事,因为创建和更新都使用post_params

Paperclip::Errors::MissingRequiredValidatorError in PostsController#create
Paperclip::Errors::MissingRequiredValidatorError

Extracted source (around line #30):

def create
  @post = Post.new(post_params)
Run Code Online (Sandbox Code Playgroud)

这是我的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    
Run Code Online (Sandbox Code Playgroud)

这是我的帖子助手

module PostsHelper
  def post_params
    params.require(:post).permit(:title, :body, :tag_list, :image)
  end
end
Run Code Online (Sandbox Code Playgroud)

如果我能补充额外的材料来帮助你,请告诉我.

ruby ruby-on-rails paperclip ruby-on-rails-4

224
推荐指数
3
解决办法
6万
查看次数

评论"frozen_string_literal:true"有什么作用?

这是rspec我项目目录中的binstub.

#!/usr/bin/env ruby
begin
  load File.expand_path("../spring", __FILE__)
rescue LoadError
end
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
  Pathname.new(__FILE__).realpath)

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rspec-core", "rspec")
Run Code Online (Sandbox Code Playgroud)

这是打算做什么的?

# frozen_string_literal: true
Run Code Online (Sandbox Code Playgroud)

ruby string immutability ruby-2.3

188
推荐指数
3
解决办法
5万
查看次数

Rspec - 结合expect_any_instance_of和接收计数

我需要验证我的类的任何实例都接收到某种方法,但我不关心是否有许多实例接收它(它们应该是).

我试过这样的:

expect_any_instance_of(MyClass).to receive(:my_method).at_least(:once)
Run Code Online (Sandbox Code Playgroud)

但显然,它只允许单个实例多次接收方法,但不允许不同的实例.

有没有办法实现这一目标?

rspec ruby-on-rails rspec-mocks

10
推荐指数
2
解决办法
3800
查看次数