sean.alien8-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009-Oct-07 14:30 UTC
output validations errors form causing type error?
Hi, I was wondering if it is possible to output validation errors in a nested form? I suppose this should be possible, but I am experiencing an error message that I can''t track down. The error I get is the following : TypeError in Store/orders#create Showing app/views/store/orders/new.html.erb where line #45 raised: can''t convert Array into String This is ocurring in the following view code: <% form_for :order, @order, :url => store_orders_url, :html => {:class => "myform"} do |order_form| %> <%= order_form.error_messages %> I can''t understand why this would be ocurring, because I was able to inspect the errors object for @order in the log, and it seems normal to me, I don''t know why it cause errors in outputting errors to the view for this object. Here is the output of the inspect method: errors object #<ActiveRecord::Errors:0x105c343c0 @errors{"customer_billing_state"=>["must be present"], "card_number"=>[["is not a valid credit card number"]], "customer_select_state"=>["^State/ Province must be a U.S. state selected from the drop down list for customers in United States"], "card_verifiation"=>[["is required"]]}, @base=#<Order id: nil, created_at: nil, updated_at: nil, customer_id: nil, gst: #<BigDecimal:105d342c0,''0.0'',9(18)>, qst: #<BigDecimal: 105d33ed8,''0.0'',9(18)>, shipping_ca: #<BigDecimal:105d33ac8,''0.0'',9(18)>, shipping_us: #<BigDecimal:105bfb840,''0.7E1'',9(18)>, currency:"USD", status: nil, comments: nil, customer_ip: "127.0.0.1", payment_method: "Credit Card", downloaded: nil, express_token: nil, express_payer_id: nil, card_type: "visa", card_expires_on: "2009-10-01">> If anyone has any idea where I can start looking to debug this error, I would appreciated it very much. Thanks, Sean
Please ignore my post, I discovered what the problem was. I had been manually adding errors to the order object from the validations of another model (active merchant''s credit card class), and my mistake was that I had added the errors directly, but the errors for each attribute are an array of errors, so instead I just need to loop through them and they add them to my order object using the errors.add method. Just in case anyone else runs into a similar problem. sean On Oct 7, 10:30 am, "sean.ali...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <sean.ali...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I was wondering if it is possible to output validation errors in a > nested form? I suppose this should be possible, but I am experiencing > an error message that I can''t track down. > > The error I get is the following : > TypeError in Store/orders#create > Showing app/views/store/orders/new.html.erb where line #45 raised: > can''t convert Array into String > > This is ocurring in the following view code: > <% form_for :order, @order, :url => store_orders_url, :html => {:class > => "myform"} do |order_form| %> > <%= order_form.error_messages %> > > I can''t understand why this would be ocurring, because I was able to > inspect the errors object for @order in the log, and it seems normal > to me, I don''t know why it cause errors in outputting errors to the > view for this object. Here is the output of the inspect method: > > errors object #<ActiveRecord::Errors:0x105c343c0 @errors> {"customer_billing_state"=>["must be present"], "card_number"=>[["is > not a valid credit card number"]], "customer_select_state"=>["^State/ > Province must be a U.S. state selected from the drop down list for > customers in United States"], "card_verifiation"=>[["is required"]]}, > @base=#<Order id: nil, created_at: nil, updated_at: nil, customer_id: > nil, gst: #<BigDecimal:105d342c0,''0.0'',9(18)>, qst: #<BigDecimal: > 105d33ed8,''0.0'',9(18)>, shipping_ca: #<BigDecimal:105d33ac8,''0.0'',9(18)>, shipping_us: #<BigDecimal:105bfb840,''0.7E1'',9(18)>, currency: > > "USD", status: nil, comments: nil, customer_ip: "127.0.0.1", > payment_method: "Credit Card", downloaded: nil, express_token: nil, > express_payer_id: nil, card_type: "visa", card_expires_on: > "2009-10-01">> > > If anyone has any idea where I can start looking to debug this error, > I would appreciated it very much. > > Thanks, > Sean