0

I have a user controller and a user model. In my user table I have limited fields. But now I want to create separate tables for user bank info and user personal info and save through the one form only. How is it possible, I am sure their must be something for this problem?

1 Answer 1

1

Check how nested_forms works along with the view helpers.

Basically you add this in your user class :

class User < AR
  has_one :profile
  has_one :address
  accepts_nested_attributes_for :profile, :adress
  attr_accessible :name, :email, :profile_attributes, address_attributes #etc
end

and in you form :

=form_for @user do |user_form|
  = user_form.text_field :name
  = user_form.field_for :profile do |profile_form|
    =profile_form.text_field :bank_name
  = user_form.field_for :address do |address_form|
    =address_form.text_field :city
Sign up to request clarification or add additional context in comments.

6 Comments

can i need to use "attribute => :accessible" method with it
Thanks a lot charlysisto it work for two models, but i have to put data i multiple tables for which it look's problematic.Is their any their solution
hi ravindra, look at my updated answer to see how to add more
i did it earlier and this trick works but doesn't show other models fields.i had tried it two day's ago.Thanks for support
"but doesn't show other models fields" ??? I don't understand, in what circumstances ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.