我正在构建一个论坛应用程序。 简而言之,该应用程序允许您询问所有用户都可以访问的主题(没有任何问题) 并且所有用户都可以回复帖子文字和与回复相关联的图片。并与回复中的图像关联有任何破损。 我使用载波来构建功能。
在终端上,我已经收到了:
NoMethodError - undefined method `reimage_will_change!' for #
<Reply:0x000055cb9f2abc30>
Did you mean? Reimage_will_change!:
app/controllers/replies_controller.rb:8:in `create'
在终端中,我注意到图像到达了创建行(第55行)。 这是此部分:
Parameters: {"utf8"=>"✓", "reply"=>{"reply"=>"Amazon CEO Jeff Bezos gave this advice to those ", "reimage"=>#<ActionDispatch::Http::UploadedFile:0x000055cb9f58cd78 @tempfile=#<Tempfile:/tmp/RackMultipart20190704-4676-zzj92m.png>, @original_filename="Capture d’écran de 2019-06-10 11-08-07.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"reply[reimage]\"; filename=\"Capture d\xE2\x80\x99\xC3\xA9cran de 2019-06-10 11-08-07.png\"\r\nContent-Type: image/png\r\n">}, "commit"=>"Envoyer", "discussion_id"=>"pourquoi-intel-a-t-il-du-mal-a-suivre-la-loi-de-moore-la-loi-de-moore-est-elle-morte"}
User Load (1.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ /home/chatln/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/activerecord-5.2.3/lib/active_record/log_subscriber.rb:98
Discussion Load (0.9ms) SELECT "discussions".* FROM "discussions" WHERE "discussions"."slug" = $1 LIMIT $2 [["slug", "pourquoi-intel-a-t-il-du-mal-a-suivre-la-loi-de-moore-la-loi-de-moore-est-elle-morte"], ["LIMIT", 1]]
↳ app/controllers/replies_controller.rb:55
Completed 500 Internal Server Error in 216ms (ActiveRecord: 25.4ms)
控制器回复
class RepliesController < ApplicationController
before_action :authenticate_user!
before_action :set_reply, only: [:edit, :update, :show, :destroy]
before_action :set_discussion, only: [:create, :edit, :show, :update, :destroy]
#before_action :find_discussions, only: [:create, :edit, :show, :update, :destroy]
def create
@reply = @discussion.replies.create(params[:reply].permit(:reply, :reimage, :discussion_id))
@reply.user_id = current_user.id
respond_to do |format|
if @reply.save
format.html { redirect_to discussion_path(@discussion) }
format.js # renders create.js.erb
else
format.html { redirect_to discussion_path(@discussion), notice: "Reponse non enregistrée, ressayer encore."}
format.js
end
end
end
def new
end
def destroy
@reply = @discussion.replies.find(params[:id])
@reply.destroy
redirect_to discussion_path(@discussion)
end
def edit
@discussion = Discussion.find(params[:discussion_id])
@reply = @discussion.replies.find(params[:id])
end
def update
@reply = @discussion.replies.find(params[:id])
respond_to do |format|
if @reply.update(reply_params)
format.html { redirect_to discussion_path(@discussion), notice: 'Reponse mise a jour...' }
else
format.html { render :edit }
format.json { render json: @reply.errors, status: :unprocessable_entity }
end
end
end
def show
end
private
def set_discussion
@discussion = Discussion.friendly.find(params[:discussion_id])
end
def set_reply
@reply = Reply.find(params[:id])
end
def reply_params
params.require(:reply).permit(:reply, :reimage, :discussion_id)
end
end
回复模型wit mount_uploader 注意:重新成像是图像回复冠军
class Reply < ApplicationRecord
mount_uploader :reimage, ReimageUploader
belongs_to :discussion
belongs_to :user
validates :reply, presence: true
extend FriendlyId
friendly_id :reply, use: [:slugged, :finders]
def should_generate_new_friendly_id?
reply_changed?
end
end
如何解决这个已经消耗了4天精力的问题