(Sorry if this ends up being a duplicate posting. I originally sent it
via gmail to the google group and I don’t know when or if it’s ever
going to show)
Maybe I’m just looking too closely… I have a simple AAA model:
class BookCover < ActiveRecord::Base
acts_as_attachment :storage => :file_system, :content_type => :image
validates_as_attachment
end
with a simple Create controller:
def create
@book_cover = BookCover.new(params[:book_cover])
if @book_cover.save
' something
else
'something else
end
redirect_to :action => ‘show’, :id => @book_cover
rescue ActiveRecord::RecordInvalid
render :action => ‘new’
end
I tried to upload an image, that was about 1.5mb in size. It would not
upload and I could not figure out why. Then I saw the docs that said
by default the max size is 1 mb. Fine, setting the :max_size to
2.megabytes let me upload my image.
My question however, is how do I trap that error / validation error?
I’m sure it’s something simple that I’m overlooking.
Thanks!
On 1/29/07, Rick O. [email protected] wrote:
validates_inclusion_of :size…
Thanks.
In the else statement of the save I redirected back to the “new” page
and I put an <%= error_messages_for :book_cover %> But didn’t see
anything displayed. I’ll have to play around some more…
john
I tried to upload an image, that was about 1.5mb in size. It would not
upload and I could not figure out why. Then I saw the docs that said
by default the max size is 1 mb. Fine, setting the :max_size to
2.megabytes let me upload my image.
My question however, is how do I trap that error / validation error?
I’m sure it’s something simple that I’m overlooking.
Should be a validation error like any other. It’s just
validates_inclusion_of :size…
–
Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com
On 1/29/07, Rick O. [email protected] wrote:
instance of your record, losing any error messages in the process.
You can use render :action => ‘new’ to show the form again, yet your
@book_cover record maintains its state from the #create action.
Ah, ok. Like I said, I was getting confused. That’s what I get from
copying and pasting from various places
Thanks!
John
Thanks.
In the else statement of the save I redirected back to the “new” page
and I put an <%= error_messages_for :book_cover %> But didn’t see
anything displayed. I’ll have to play around some more…
john
Redirecting will start a brand new request that usually creates a new
instance of your record, losing any error messages in the process.
You can use render :action => ‘new’ to show the form again, yet your
@book_cover record maintains its state from the #create action.
–
Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com