I have two models. call.rb which has_many :visits and visit.rb which belongs_to :call. After populating call from the form which then shows all the parameters including the call.id I then make a visit corresponding to the call. the form for the new visit creates a new record ok and shows the input information except for I have it show me the call_id which is the foreign key and it tells me that it is nill when I look at the record in the ruby console. So it never associates the visit with the corresponding call. my call.rb is as follows
class Call < ActiveRecord::Base ALL_FIELDS = %w(name address age area sex notes) VALID_SEX = ["Male", "Female"] validates_presence_of :name, :address, :age, :area validates_inclusion_of :sex, :in => VALID_SEX, :message => "must be male or female" has_many :visits, :foreign_key => 'call_id'
end the visit.rb is as follows
class Visit < ActiveRecord::Base belongs_to :call, :class_name => 'Call', :foreign_key => 'call_id' end
my CallsController is
class CallsController < ApplicationController
def index @call = Call.find(:first, :order => 'RANDOM()') end
def new @call = Call.new end
def create @call = Call.new(params[:call]) if @call.save flash[:notice] = "Call submission succeded" render :action => 'show' else render :action => 'new' end end
def show @call = Call.find(params[:id]) end end
My visits controller is
class VisitsController < ApplicationController
def index end
def show @visit = Visit.find(params[:id]) end
def new @visit = Visit.new end
def create @visit = Visit.new(params[:visit]) if @visit.save flash[:notice] = "Visit submission succeded" render :action => 'show' else render :action => 'new' end end
end And my schema after migrations is ActiveRecord::Schema.define(:version => 6) do
create_table "calls", :force => true do |t| t.string "name" t.string "address" t.string "age" t.string "area" t.date "date" t.datetime "created_at" t.datetime "updated_at" t.string "sex", :default => "Male" t.text "notes" end
create_table "visits", :force => true do |t| t.integer "call_id" t.datetime "created_at" t.datetime "updated_at" t.string "name" t.string "address" t.date "date" t.string "placement" t.string "time_of_day" t.text "topic" t.text "next_topic" end
end
Any help for a noob will be much greatly appreciated