0

Hello again

I am trying to show the errors that can occur by uploading a file (file name, size).
I tried to modify this code cut-off but I could not.

else
            format.html { render action: "new" }
            format.json { render json: @upload.errors, status: :unprocessable_entity }
          end

I have following validations and I want json to write when an error occured, so something like this:

else
            format.html { render action: "new" }
            format.json { render json: @upload.errors, status: :unprocessable_entity, error:"Error!" }
          end

(it doenst work) and I need a specification of an error, that is written in a validation :message

my validations:

validates :upload_file_name,  :presence   => true,
                                :format     =>{:with => %r{\.(cel)$}i}

  validates_uniqueness_of :upload_file_name, :message => "File with this name is already in the database"

  validates :upload_file_size,  :inclusion  => {:in =>10.megabytes..20.megabytes}, :message =>"Too big or too small"

  def to_jq_upload
    {
      "name" => read_attribute(:upload_file_name),
      "size" => read_attribute(:upload_file_size),
      "url" => upload.url(:original),
      "delete_url" => upload_path(self),
      "delete_type" => "DELETE" 
    }
  end

end

Thanks in advanced

2
Contributors
1
Reply
7
Views
4 Years
Discussion Span
Last Post by LastMitch
0

I am trying to show the errors that can occur by uploading a file (file name, size).

I'm not sure what you are asking.

You never mention what uploading file you are using.

Plus I got no idea what language for the upload file you are using.

You can try this is and see if the message appears:

else
format.html { render action: "new" }
render json: {error: @json.upload.errors.full_messages}, status: :unprocessable_entity 
end
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.