My app has a 'page' model and a 'category' model. 'Page' belongs_to :category. 'Category' has_many :pages.
From the console I can create and save a page object with no problems:
p = Page.new
#<Page id: nil, title: nil, body: nil, created_at: nil, updated_at: nil, published: nil, read_counter: nil, category_id: nil>
p.title, p.body, p.category_id = "Test", "Test", "1"
#<Page id: nil, title: "Test", body: "Test", created_at: nil, updated_at: nil, published: nil, read_counter: nil, category_id: 1>
p.save
=> true
Yet, when I submit the same data in a post request to my controller, 'category_id' is being ignored.
The page object is created in my controller thus: @page = Page.new(params[:page])
If I write the contents of 'params[:page]' to WEBrick, I see: {"title"=>"Test", "body"=>"Test", "category_id"=>"1"}
If I write the contents of @page to the WEBrick, I see: #<Page id: nil, title: "Test", body: "Test", created_at: nil, updated_at: nil, published: nil, read_counter: nil, category_id: nil>
I get the same result on the console:
params = {"title"=>"Test", "body"=>"Test", "category_id"=>"1"} p = Page.new(params)
#<Page id: nil, title: "Test", body: "Test", created_at: nil, updated_at: nil, published: nil, read_counter: nil, category_id: nil>
p.save
=> false
Does anyone have any tips they can give me? Am I missing something really obvious?
Thanks in advance