# Can save object via console, but not in app's controller

**URL:** <https://www.ruby-forum.com/t/can-save-object-via-console-but-not-in-apps-controller/193319>\
**Category:** Rails\
**Created:** [August 15, 2010, 9:17pm UTC](https://www.ruby-forum.com/t/can-save-object-via-console-but-not-in-apps-controller/193319 "2010-08-15T21:17:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jimb](https://www.ruby-forum.com/u/jimb)\
**Post date:** [August 15, 2010, 9:17pm UTC](https://www.ruby-forum.com/t/can-save-object-via-console-but-not-in-apps-controller/193319/1 "2010-08-15T21:17:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jimb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@jimb](https://www.ruby-forum.com/u/jimb)\
**Post date:** [August 15, 2010, 9:23pm UTC](https://www.ruby-forum.com/t/can-save-object-via-console-but-not-in-apps-controller/193319/2 "2010-08-15T21:23:57Z")

</div>

Please ignore my question.

Changed: attr\_accessible :category  
into:  
attr\_accessible :category\_id  
and it works now.

Doh!  
Checked, double checked and tripple checked before posting, but still I  
missed that!
