Hi rails list, I am doing some testing with Ruby on Rails and enjoying it very much. I think an important method for learning Rails is to make use of the debug() method to get an idea of what an object looks like but it''s unclear to me what the meaning of some parts of the debug output is. For example take this output: --- &id001 !ruby/object:Person attributes: username: julian id: 1 company_id: 1 company: !ruby/object:Company attributes: name: Capital ICT id: "1" street: Hoofdstraat 56 errors: !ruby/object:ActiveRecord::Errors base: *id001 errors: {} --- (The Person object is associated to the Company object through a ''belongs_to" association) My questions are: - what is the &id001 in the first line? - why are the username, id and company_id all unquoted, while id and company_id are both INTs in the db - why is id in the Company object quoted (it''s an INT in the db) -what does the errormessage at the end of the output mean Best regards, Julian Wegkamp The Netherlands
> - what is the &id001 in the first line?I think that''s because its a pointer of some kind. Anyone else know the details?> - why are the username, id and company_id all unquoted, while id and > company_id are both INTs in the dbActive Record performs lazy type conversions, so the attributes are not converted to their proper types before you attempt to access them. This is a big deal when you want to loop over 100 rows that all needs an expensive date conversion.> - why is id in the Company object quoted (it''s an INT in the db)Same deal, lazy type conversions.> -what does the errormessage at the end of the output meanThat''s not an error, but rather just an error container that is used to hold the errors generated by validate and friends. If there''s anything in here, .save will fail. -- David Heinemeier Hansson, http://www.basecamphq.com/ -- Web-based Project Management http://www.rubyonrails.org/ -- Web-application framework for Ruby http://macromates.com/ -- TextMate: Code and markup editor (OS X) http://www.loudthinking.com/ -- Broadcasting Brain
On Sun, Dec 12, 2004 at 01:42:45PM +0100, David Heinemeier Hansson wrote:> >- what is the &id001 in the first line? > > I think that''s because its a pointer of some kind. Anyone else know the > details?I believe this is because the @base attribute within the Errors object contains an instance of the AR model object which itself contains the Rrror object so there is a loop there that yaml isn''t going to traverse ;) marcel -- Marcel Molina Jr. <marcel-WRrfy3IlpWYdnm+yROfE0A@public.gmane.org>
It would be nice if custom handling of public errors didn''t require diving into rescue.rb. Ideally: - We could write custom templates for arbitrary errors - We could use two different templates for public and private handling - We could specify the response code based upon exception class - We could use the same template for more than one error - Missing templates would fall back to a generic template (as they do now.) To implement these changes: - .../templates/rescues be changed to hold subdirs private/ public/ and possibly common/ - Configuration support be added for specifying response codes and exception templates. It would be best if only special cases had to be configured. Default template names could be guessed using the inflector; the default response code could be configurable or simply "500 Internal Error" as it is now. Another option might be app specific error templates, but this is (even) less of a priority. These changes are obviously not a priority, and they might not even be liked by all. So, what are your thoughts: should this be implemented? Is it necessary or does it fall outside the rule of ''less software?''
Not sure if this is exactly what you mean, but there is the resue_action_in_public method[1] You''ll need to add the following to one of your enviroment files (like production.rb): ActionController::Base.consider_all_requests_local = false In my case, I have a custom template that displays the error: def rescue_action_in_public(exception) @exception = exception render ''rescues/error'' end Granted, the method above is rather "dumb" since its not really showing any friendlier error msgs than what rails spits out, but at least it integrates better in a site than the standard rails error pages. I guess you could flesh out the above with more logging, translation of rails errors to "user friendly errors", or sending of emails to admin etc. [1] http://api.rubyonrails.org/classes/ActionController/Rescue.html#M000006 -- johan On Sun, 12 Dec 2004 17:55:26 -0500, Nicholas Seckar <nseckar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It would be nice if custom handling of public errors didn''t require > diving into rescue.rb. > > Ideally: > - We could write custom templates for arbitrary errors > - We could use two different templates for public and private handling > - We could specify the response code based upon exception class > - We could use the same template for more than one error > - Missing templates would fall back to a generic template (as they do now.) > > To implement these changes: > - .../templates/rescues be changed to hold subdirs private/ public/ > and possibly common/ > - Configuration support be added for specifying response codes and > exception templates. > > It would be best if only special cases had to be configured. Default > template names could be guessed using the inflector; the default > response code could be configurable or simply "500 Internal Error" as > it is now. > > Another option might be app specific error templates, but this is > (even) less of a priority. > > These changes are obviously not a priority, and they might not even be > liked by all. So, what are your thoughts: should this be implemented? > Is it necessary or does it fall outside the rule of ''less software?'' > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Johan Sørensen Professional Futurist www.johansorensen.com