用于#的未定义方法`bson_type'

问题描述 投票:1回答:2

我正在使用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
ruby-on-rails mongodb ruby-on-rails-4.1
2个回答
1
投票

你尝试过使用mongoid-paperclip吗?

如果你想一起使用mongodb和paperclip,那么使用mongoid-paperclip可以解决你所有的问题。

您可以通过其他方式帮助我们解答

  • 目前尚不清楚控制器的名称是什么。请添加整个班级,以便清楚地显示名称。
  • 目前尚不清楚你得到的错误是哪一行。你应该能够告诉我们。
  • 如果您在此处粘贴整个错误消息,则总是更加清晰。甚至一点点堆栈跟踪。
  • 告诉我们当您收到错误时用户尝试执行的操作。
  • 向我们提供您的路线可能会有所帮助

0
投票

可能是第一次不允许使用参数。你应该先做new_params = params.permit!.to_h,然后再使用它。

更好的是,只允许你需要的东西。

© www.soinside.com 2019 - 2024. All rights reserved.