Friday, August 17, 2012

[Rails] Re: Rails doesn't validate create_model or build_model (has_one association)

Colin Law wrote in post #1072628:
> On 17 August 2012 01:30, network DB <lists@ruby-forum.com> wrote:
>> I've got User has_one Shop. Rails is not validating when I tried
>> create_shop or build_shop, neither in the browser nor the rails console.
>
> Those methods create the object but do not save it (see section
> 4.1.1.3 in the Rails Guide on Associations). Validation happens when
> the record is saved (or valid? is called).
>
> Colin

Yeah but in the browser, it just went straight to the show action
without showing any validation warning at all. If it fails validation,
it should render the shops#new action again.

Here's the error message it gives me when I click submit in the
shops#new form without inputting anything and then it tried to go to the
show action:

Routing Error

No route matches {:action=>"show", :controller=>"shops", :id=>#<Shop id:
nil, user_id: 1, name: "", primary_address: "", secondary_address: "",
city: "", postal_code: "", state_code: nil, country_code: "", phone: "",
email: "", website: "", facebook: "", twitter: "", opening_hours: "",
description: "", latitude: nil, longitude: nil, logo: nil, currency:
"AED", created_at: nil, updated_at: nil>}

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate