File-column plugin file size validation?

Anyone had success with this?

i tried this:

validate :check_file_size

def check_file_size

if @picture and @picture.size > 50000

errors.add(‘picture’, ‘too big’)



def picture



def picture=(picture)



as you can see, it’s been commented out because it well, doesn’t work…


try putting this in your user model

validates_filesize_of :file, :in => 0…3.megabyte

This worked, thanks for pointing this out. in addition, i guess there’s

validates_file_format_of :image, :in => [“gif”, “png”, “jpg”]
validates_image_size :image, :min => “1200x1800”

I’m having an issue with the validation. I have …

validates_filesize_of :avatar, :in => 0.kilobytes…40.kilobytes
validates_file_format_of :avatar, :in => [“gif”, “png”, “jpg”]

It’s catching everything fine but the problem is when the form refreshes
it displays the most recent uploaded picture (in this case) from the tmp
folder. So if I uploaded an image that was too big it will display that

Any thoughts?

Jon Minori wrote:

Any thoughts?

You can try something like

<% if model.errors.on(:avatar) %>
Invalid avatar
<% else %>
<%= image_tag url_for_image_column(‘model’, ‘avatar’) %>
<% end %>

We develop, watch us RoR, in numbers too big to ignore.

Yeah that seems like a pretty simple solution. Thank you!