Hey, I'm trying to toss together an application and I've been stuck on this part for a while.
I have a user object that looks like
I'm trying to get...
...thatched onto it, so my code looks more beautiful.
Employee will look like...
Employee.dob Employee.position_title Employee.origindate Employee.departure_date
Here's my working console output, so I must be on the right track
[email protected]:/home/kentos/dev/rails/xpd3# r c Loading development environment (Rails 3.0.7) ruby-1.9.2-p180 :001 > u = User.last => #<User id: 100, email: "[email protected]", encrypted_password: "e3f71a9a44686493130023e303473a8a46a2ed3f7b6c714c2d8...", created_at: "2011-11-26 14:35:11", updated_at: "2011-11-26 14:35:11", salt: "89173dc006c3f5a668cdb537538c7d6aeaf3610c6a387149cd1...", admin: false> ruby-1.9.2-p180 :002 > u.employee = Employee.new => #<Employee id: 5, employeeid: nil, name: nil, position_title: nil, origin_date: nil, dob: nil, created_at: "2011-12-12 02:59:23", updated_at: "2011-12-12 02:59:23", user_id: 100> ruby-1.9.2-p180 :003 >
But my controller chokes =(
My Models look like this
class User < ActiveRecord::Base attr_accessor :password attr_accessible :email, :password, :password_confirmation has_one :employee, :dependent => :destroy . . . end
class Employee < ActiveRecord::Base attr_accessible :name, :email, :positiontitle, :dob, :origindate belongs_to :user end
And my controller looks like this:
class EmployeesController < ApplicationController def index @employee = Employee.new end # When the user clicks "Make User employee" this method fires up # And sets it up def create # Get User by username... @user = User.where(:email => params[:user][:email]) # Make sure user is not already set to an employee [email protected] = Employee.new e = Employee.new #p e @user.employee = e #create()#params[:employee]) # print "Employee Created!" end def destroy end end
This is the error I get while it's trying to get through employees#create
undefined method `employee=' for #<ActiveRecord::Relation:0xa093684>
This post has been edited by NotarySojac: 11 December 2011 - 08:21 PM