Reputation: 5250
The attached image is not retained if I validate the form with model . We use paperclip gem 'paperclip', "~> 3.4.0". I follow the following steps.
Steps:
The form has fields like
company_name(mandatory)
location,
object_type,
object_size(mandatory) and
attachment(mandatory).
1.Fill the fields company_name(mandatory),location,object_type and attach an image 2.Not to fill object_size(mandatory) which has model validation. 3.click on submit and the model validation is shown but the attached image disappear.
(Note: If the form is correctly filled at the first time the image is retained properly and stored in s3 database)
Can anybody help me plz.
Upvotes: 1
Views: 310
Reputation: 2999
You only need a file field in your form, the other three default paperclip object properties do not require form fields and are set through metadata tags on the image.
<p>
<%= f.label :avatar, "Select Profile Picture*" %><br />
<%= f.file_field :avatar %>
</p>
To validate use this in your model:
validates :avatar, :attachment_presence => true,
:attachment_content_type => { :content_type => [ 'image/png', 'image/jpg', 'image/gif', 'image/jpeg' ] }
Upvotes: 3
Reputation: 4956
You can't assign a file field a value, its a security risk
Example:
<form id="bad_form" action="/my_url">
<input type="file" value="/Users/bob/my_very_secret_file.txt">
</form>
<script>
$('#bad_form').submit();
</script>
Upvotes: 0