(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! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 Olson http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/29/07, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > 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... >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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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.. > > johnRedirecting 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 Olson http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/29/07, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > 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.Ah, ok. Like I said, I was getting confused. That''s what I get from copying and pasting from various places :) Thanks! John --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---