Let's consider following example:
# .../pitches_controller.rb
def upload_avatar
pitch = Pitch.find(params[:id])
form = PitchAvatarForm.new(pitch)
if form.validate(pitch_avatar_params)
form.save
on_pitch_avatar_upload_succeeded(form)
else
on_pitch_avatar_upload_fialed(form)
end
end
# .../forms/pitch_avatar_form.rb
class PitchAvatarForm < Reform::Form
model :pitch
property :image
property :image_file_name
property :image_content_type
property :image_file_size
validates :image,
file_content_type: { allow: ['image/jpeg', 'image/jpg', 'image/png'] },
file_size: { less_than: 2.megabytes }
end
On each form#save execution it couses following error:
form.save
NoMethodError: undefined method `sub' for nil:NilClass
from /Users/rapide/.rvm/gems/ruby-2.3.0@bttf/gems/paperclip-4.2.2/lib/paperclip/storage/s3.rb:255:in `s3_object'
I fixed this issue by assigning attributes to the pitch before creating the form but it looks like an ugly hack. Any idea how to solve this in better way?
Let's consider following example:
On each
form#saveexecution it couses following error:I fixed this issue by assigning attributes to the pitch before creating the form but it looks like an ugly hack. Any idea how to solve this in better way?