1

Given the following models:

User.rb

NetworkDepartment.rb (id, title,added_by)
  belongs_to :user, :foreign_key => :added_by

I want to be able to create a network department and have the added_by assigned automatically. I have the following:

@network_department = current_user.network_departments.new(params[:network_department])

Why isn't current_user automatically setting added_by as the current_user.id ?

Thanks

AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012

1 Answers1

1

Do you have has_many :network_departments in User? That should do it. Otherwise try current_user.network_departments.build(params[:network_department])

Austin
  • 3,860
  • 3
  • 23
  • 25