enter image description hereI have added a page to complete his profile after creating an account indicating only the e-mail address and password, so we find ourselves on the page that completes his profile, add photos to His account ... everything works well if I fill the fields correctly and I upload photos, I can validate and my profile is updated, the problem comes when I forget to fill a mandatory field (example: address or first_name. ..) and that I had already upload a photos, so I have a render that tells me that I forgot fields and when I complete them and validate, it is that cloudinary makes a mistake
ActiveRecord::RecordNotFound in UsersController#update
Couldn't find Attachinary::File with 'id'=18
params :
<ActionController::Parameters {"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"TaAxCldr0Hi2r81Oat3i9ERK8TWapiICbCeyf7J3oR6UDVSnqEoNsOjcJ6ms9Ms8MOPlYUc7mKL9A4sp+Hg4IQ==", "user"=><ActionController::Parameters {"last_name"=>"fezfzgz", "first_name"=>"gzrgrzg", "birthday(1i)"=>"2013", "birthday(2i)"=>"8", "birthday(3i)"=>"22", "gender"=>"homme", "website"=>"zesvzzeze", "phone_number"=>"102030405", "avaibility"=>"false", "description"=>"", "address"=>"zregregreg", "zip_code"=>"13210", "city"=>"france", "photos"=>["[{\"id\":18,\"public_id\":\"j3b5qdc90jj77ygib26f\",\"version\":\"1503409614\",\"format\":\"jpg\",\"resource_type\":\"image\",\"path\":\"v1503409614/j3b5qdc90jj77ygib26f.jpg\"}]"], "videos"=>[""], "voice_attribute"=>"grave", "voices"=>[""]} permitted: false>, "commit"=>"Save", "controller"=>"users", "action"=>"update", "id"=>"18"} permitted: false>
current_user :
#<User id: 18, email: "davqcze@freel.fr", created_at: "2017-08-22 13:46:21", updated_at: "2017-08-22 13:46:21", first_name: "gzrgrzg", last_name: "fezfzgz", birthday: nil, website: "zesvzzeze", role: "actor", gender: "homme", phone_number: "102030405", voice_attribute: "grave", description: "", avaibility: false, address: "zregregreg", zip_code: "52458", city: "france">
Users controller :
class UsersController < ApplicationController
def index
@users = User.all
end
def edit
@user = User.find(params[:id])
end
def show
@user = User.find(params[:id])
@booking = Booking.new
end
def update
@user = current_user
if current_user.DA?
if @user.update(user_params_da)
redirect_to user_path(current_user)
else
render :edit
end
else
if @user.update(user_params)
redirect_to user_path(current_user)
else
render :edit
end
end
end
def user_params
params.require(:user).permit(
:first_name, :last_name, :phone_number, :address, :city, :birthday,
:website, :avaibility, :description, :zip_code, :gender, :voice_attribute,
voices: [], videos: [], photos: []
)
end
def user_params_da
params.require(:user).permit(
:first_name, :last_name, :phone_number, :address, :city, :birthday,
:website, :description, :zip_code, :gender
)
end
end
user model :
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :bookings
has_many :projects
has_attachments :photos, maximum: 10 #limiting upload to 10 units
has_attachments :videos, maximum: 10 #limiting upload to 10 units
has_attachments :voices, maximum: 10 #limiting upload to 10 units
validates :first_name, presence: :true, on: :update, unless: :devise?
validates :last_name, presence: :true, on: :update, unless: :devise?
validates :zip_code, presence: :true, on: :update, unless: :devise?
validates :address, presence: :true, on: :update, unless: :devise?
validates :city, presence: :true, on: :update, unless: :devise?
validates :phone_number, presence: :true, on: :update, unless: :devise?
validates :gender, presence: :true, on: :update, unless: :devise?
validates :birthday, presence: :true, on: :update, unless: :devise?
with_options if: :actor? do |actor|
actor.validates_inclusion_of :avaibility, :in => [true, false], on: :update
actor.validates :voice_attribute, presence: :true, on: :update
actor.validates :voice_attribute, presence: :true, on: :update, unless: :devise?
end
enum voice_attribute: [:grave, :moyen, :aigu]
enum gender: [:femme, :homme]
enum role: [:DA, :actor]
private
def devise?
email_changed? || encrypted_password_changed?
end
end
https://preview.ibb.co/fxVW45/Capture_du_2017_08_22_23_52_21.png