Let me preface by saying i’m a total noob at ruby/rails.
For some reason, I am just not grasping the concept of has_one &
I’m working on a project that includes user authentication, and 3
different types of user profiles.
User profiles are either “fan”, “band”, or “venue” objects, and user
logins are “user” objects.
Just working with the “fan” profiles now.
I have the following tables:
user_id (foreign key)
In User model:
class User < ActiveRecord::Base
In Fan model:
class Fan < ActiveRecord::Base
@user = User.new(@params[:user])
session[:user] = User.authenticate(@user.login,
flash[:message] = “Signup successful”
redirect_to :controller => ‘fan’, :action => “new”
flash[:warning] = “Signup unsuccessful”
@fan = Fan.new
@fan = Fan.new(params[:id])
@user.fan << @fan
flash[:notice] = ‘Your Fan Profile was successfully created.’
redirect_to :action => ‘list’
render :action => ‘new’
The goal is, when a new user signs up, after creating their login info,
they get to create their “fan” profile, and when it is saved, the
profile is saved in the fans table, with the appropriate user_id
assigned to it.
As I currently have it, the user signup works, then takes me to the new
profile form, but when I try to save, I get:
NoMethodError in FanController#create
You have a nil object when you didn’t expect it!
The error occured while evaluating nil.fan
Application Trace | Framework Trace | Full Trace
line 28 is ‘@user.fan << @fan’
i’ve tried @user.fan = @fan, that doesn’t work…
I keep reading and reading about this, and I just can’t seem to get a
handle on it yet. I’m in dire need of help!