I have 3 models that are basically nested.
class User < ActiveRecord::Base
attr_accessible :birthday, :name
has_one :advancement, :dependent => :destroy
accepts_nested_attributes_for :advancement
attr_accessible :advancement_attributes
end
class Advancement < ActiveRecord::Base
attr_accessible :user_id, :rank_name
belongs_to :user
has_one :rank, :dependent => :destroy
accepts_nested_attributes_for :_rank
attr_accessible :rank_attributes
end
class Rank < ActiveRecord::Base
attr_accessible :advancement_id, :one_li, :one_pi, :one_date, ...
belongs_to :advancement
end
Here is the controller code I use to create my models.
class UsersController < ApplicationController
def new
@user = User.new
@user.advancement = Advancement.new
@user.advancement.rank = Rank.new
respond_to do |format|
format.html # new.html.erb
end
end
def create
@user = User.new(params[:user])
@user.advancement = Advancement.new
@user.advancement.rank = Rank.new
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
else
format.html { render action: "new" }
end
end
end
end
In the console I can create relations that work like I would expect. When I try to do this through the browser all of my objects are instantiated, the foreign keys are correct, but if I try to find user.advancement, I get a method missing error. Am I using new or create wrong and if so what should I do? Sorry about the amount of code, but I didnt know any other way to explain it.
To start, in most of your code you reference a “rank” model but the model itself appears to be called “BoyScoutRank”. Could this be the issue?