Rails 4 different validations in one model -
i have page 2 tabs (forms), used edit 1 object.
e.g. user's info. in first tab there personal info, in next tab there billing info.
each form has own submit button. how can validate fields separately. if understood right, when i'll try submit form 4 fields (of 10), raise errors, other fields (6 of 10) wrong.
what right way this?
create 2 classes reflect ui:
class user has_one :user_info has_one :billing_info end class userinfo belongs_to :user # add validation end class billinginto belongs_to :user # add validation end
in controller:
def edit @user = user.find(params[:id]) @user_info = @user.build_user_info @billing_info = @user.build_billing_info end
then in views:
= form_for @user_info |f| = form_for @billing_info |f|
you'll need 2 controllers handle post
requests. should named userinfoscontroller
, userbillinginfoscontroller
respectively.
Comments
Post a Comment