Я пытаюсь добавить поле изображения в форму ответа на моем новом форуме по типу приложения.
приложение содержит основной sujet, и все подключенные пользователи могут ответить в разделе replie.
Теперь я пытаюсь добавить поле изображения более старого текстового поля.
я использую carrierwave для реализации этой функции.
но я получаю это сообщение об ошибке в терминале:
NoMethodError - undefined method `reimage_will_change!' for #
<Reply:0x000055cb9f2abc30>
Did you mean? Reimage_will_change!:
app/controllers/replies_controller.rb:8:in `create'
почему рельсы подчинения: reimage_will_change:
my я использовал "reimage" это переменное поле.
см. Полное сообщение termianl:
Started POST "/discussions/pourquoi-intel-a-t-il-du-mal-a-suivre-la-loi-de-moore-la-loi-de-moore-est-elle-morte/replies" for ::1 at 2019-07-04 10:12:20 +0000
(1.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
↳ /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
Processing by RepliesController#create as JS
Parameters: {"utf8"=>"✓", "reply"=>{"reply"=>"Amazon CEO Jeff Bezos gave this advice to those ", "reimage"=>#<ActionDispatch::Http::UploadedFile:0x000055d560cc1150 @tempfile=#<Tempfile:/tmp/RackMultipart20190704-14120-1uwpx6n.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.3ms) 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.8ms) 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 225ms (ActiveRecord: 24.9ms)
####
NoMethodError - undefined method `reimage_will_change!' for #<Reply:0x00007ffb6c716fa0>
Did you mean? Reimage_will_change!:
app/controllers/replies_controller.rb:8:in `create'
Я думаю, что ошибка происходит из строки 55 контроллера ответов на уровне set_discussion.
def set_discussion
@discussion = Discussion.friendly.find(params[:discussion_id])
end
и replies_controller complete
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
и ответы модели
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