Hello I have the following models.
The User Model:
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation
has_one :user_informations
has_secure_password
end
The UserInformation Model:
class UserInformation < ActiveRecord::Base
belongs_to :user
attr_accessible :address, :address2, :business, :descripcion, :identification_number, :mobile_cell, :name, :phone_number
end
Now I need to create the view and the controller to create and update the user information, and I have many questions:
1) how can I generate the controller:
rails g controller UserInformations
o
rails g controller UserInformation
2) how my new, create and update action know the user ID.
3) how can I set the routes for this user information
Thanks. Maybe these are a basic question, but I’m new in rails and I don’t know how to do all of this.
Thanks again for your help.
1) You have to use pluralize for controller, so
rails g controller UserInformationswill work.2 + 3) You can set up Restful routes:
With above routes you will have path
users/:id/user_information, so you can know your user ID throughparams[:id], ex, in your create or update action you can use:to find which user is shown informaton.