Hello guys, I''m new in rails and I have the following question:
I have two model
user and user_informacion:
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation
has_one :user_information
has_secure_password
before_save { |user| user.email = email.downcase }
before_save :create_remember_token
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, presence: true, length: { minimum: 6 },
confirmation: true, unless: Proc.new { |a| !a.new_record? &&
a.password.present? }
def send_password_reset
self.password_reset_token = SecureRandom.urlsafe_base64
self.password_reset_at = Time.zone.now
self.password = self.password
self.save!(:validate => false )
UserMailer.password_reset(self).deliver
end
def reset_password_token
self.password_reset_token = nil
self.password_reset_at = nil
save!
end
private
def create_remember_token
if self.new_record?
self.remember_token = SecureRandom.urlsafe_base64
end
end
end
class UserInformation < ActiveRecord::Base
belongs_to :user
attr_accessible :address, :address2, :business, :descripcion,
:identification_number, :mobile_cell, :name, :phone_number
validates :address, presence: true, length: { :maximum => 250 }
validates :address2, length: { :maximum => 250 }
validates :descripcion, presence: true, length: { :maximum => 300 }
validates :identification_number, presence: true
validates :phone_number, presence: true, length: { :is => 11 }
validates :mobile_cell, :length => { :is => 11 }
validates :user_id, presence: true
end
As you can see User has_one UserInformation
My routes are like this:
resources :users do
member do
resource :user_information
end
end
resources :sessions, only: [:new, :create, :destroy]
resources :password_resets
root to: ''users#new''
match ''/signup'', to: ''users#new''
match ''/signin'', to: ''sessions#new''
match ''/signout'', to: ''sessions#destroy'',
via: :delete
I having a lot of problem tying to figure out how to make a form_for for my
create action of my user_information. I tried with
form_form(@user_information) do |f|, form_for([user,
user.user_information.build]) do |f| but I always get an error. Does anyone
can help me with this form_fom, please??? The form_for if for my new view
of may user_information.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/kLrf8MgfytEJ.
For more options, visit https://groups.google.com/groups/opt_out.