我正在使用rails 4版本。我使用MongoDb作为我的项目的数据库。我想执行上传操作,因为我正在使用“paperclip gem”。我收到了上述错误。实际上错误发生在NoMethodError
的候选控制器CandidatesController#create_image
中。请帮我解决这个问题。
如果要上传任何其他方法,这与mongoid兼容,请帮助我获得解决方案。
这是我的候选人控制器动作:
def profile
@candidate = Candidate.find(params[:id])
@image = Image.new
end
def create_image
@candidate = Candidate.find(params[:id])
@image = Image.new(new_image)
@user = current_user
if @image.save
redirect_to profile_user_candidate_path(@user.id.to_s, @candidate.id.to_s)
end
end
private
def new_image
params.require(:image).permit(:logo, :candidate_id)
end
这是我的图像控制器
class ImagesController < ApplicationController
def index
@images = Images.all
end
def new
@image = Image.new
end
def show
@id = params[:id]
@image = Image.find(@id)
end
def create
@image = Image.new(params[:image])
if @image.save
redirect_to :action => :show, :id => @image.id
end
end
private
def image
params.require(:image).permit
end
end
如果你想一起使用mongodb和paperclip,那么使用mongoid-paperclip可以解决你所有的问题。
可能是第一次不允许使用参数。你应该先做new_params = params.permit!.to_h
,然后再使用它。
更好的是,只允许你需要的东西。