1

我正在使用 Rails 4 版本。我正在使用 MongoDb 作为我的项目的数据库。我想执行上传操作,因为我正在使用“回形针宝石”。我收到上述错误。实际上错误是在候选人控制器NoMethodErrorCandidatesController#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
4

2 回答 2

1

您是否尝试过使用mongoid-paperclip

如果您想同时使用 mongodb 和回形针,那么使用mongoid-paperclip可能会解决您的所有问题。

您可以帮助我们回答的其他方式

  • 目前尚不清楚控制器的名称是什么。请添加整个班级,以便名称清晰。
  • 目前尚不清楚您在哪一行得到错误。你应该可以告诉我们。
  • 如果您将整个错误消息粘贴到此处,总是会更清楚。甚至一点堆栈跟踪。
  • 告诉我们当您收到错误时用户正在尝试做什么。
  • 还给我们您的路线可能会有所帮助
于 2014-04-02T14:35:13.297 回答
0

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

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

于 2018-09-05T17:08:52.710 回答