ruby on rails - How to fix 'You cannot call create unless the parent is saved' error when trying to upload images? -


when try upload image rails app, check whether it's below 3 mega pixels , remove if it's below value. if image above 3mp works. if it's below 3mp, gives me error you cannot call create unless parent saved

the photo create function :

def create     @photo = current_user.photos.build(file: params[:file])     if @photo.save!(:validate => false)         respond_to |format|             format.json{ render :json => @photo }         end     end end 

the check mega pixel function :

after_create :check_mp before_save :set_mrdocs_rejects before_create :new_workflow_state validates :title, :description, :category_id, :tag_list, presence: true before_save :custom_corrections after_save :accept_or_reject, :submit_photo validate :custom_validations  def check_mp     @min_mp = setting.find_by_key('min_megapixel').value.to_i     @mp = ((self.width * self.height) / 1000000.0).round     if @mp < @min_mp         rejected = self.user.rejected         rejected << self.originalname         self.user.update_attribute(:rejected, rejected)          self.destroy     end end 

what might causing error?


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -