# Form and Symbol

**URL:** <https://www.ruby-forum.com/t/form-and-symbol/81521>\
**Category:** Rails\
**Created:** [January 9, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/form-and-symbol/81521 "2007-01-09T16:52:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![AurSSSSlien\_Bottazi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@AurSSSSlien\_Bottazi](https://www.ruby-forum.com/u/AurSSSSlien_Bottazi)\
**Post date:** [January 9, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/form-and-symbol/81521/1 "2007-01-09T16:52:05Z")

</div>

I am new to ruby on rails. I checked online and on many tutorials but  
I can’t find an answer to my problem ☹

As an exercise I am creating a weblog

I am using a simple form to add a new “page” to my weblog

Form code:  
\<%= error\_messages\_for ‘page’ %\>

Title  
\<%= text\_field 'page', 'title' %\>

Created at  
\<%= datetime\_select 'page', 'created\_at' %\>

Content  
\<%= text\_area 'page', 'content' %\>

and in the controller I use

@page = Page.new(params[:page])

It works but I need to modify the parameters I am sending to Page.new()

I know I can’t modify :page as it is a Symbol.  
But how can I access the values contained inside :page?

I have tried b = eval(:a.id2name) to get the variable’s contents but  
id does not work.

Any idea?

---

<div class="post-metadata">

**Author:** ![AurSSSSlien\_Bottazi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@AurSSSSlien\_Bottazi](https://www.ruby-forum.com/u/AurSSSSlien_Bottazi)\
**Post date:** [January 9, 2007, 7:07pm UTC](https://www.ruby-forum.com/t/form-and-symbol/81521/2 "2007-01-09T19:07:16Z")

</div>

AurÃ©lien Bottazini wrote:

> I am new to ruby on rails. I checked online and on many tutorials but  
> I can’t find an answer to my problem ☹
> 
> As an exercise I am creating a weblog
> 
> I am using a simple form to add a new “page” to my weblog
> 
> Form code:  
> \<%= error\_messages\_for ‘page’ %\>
> 
> Title  
> \<%= text\_field 'page', 'title' %\>
> 
> Created at  
> \<%= datetime\_select 'page', 'created\_at' %\>
> 
> Content  
> \<%= text\_area 'page', 'content' %\>
> 
> and in the controller I use
> 
> @page = Page.new(params[:page])
> 
> It works but I need to modify the parameters I am sending to Page.new()
> 
> I know I can’t modify :page as it is a Symbol.  
> But how can I access the values contained inside :page?
> 
> I have tried b = eval(:a.id2name) to get the variable’s contents but  
> id does not work.
> 
> Any idea?

You can use either:

params[:page][:content]

if you wanted to edit the values before putting it into the Page object  
or

@page.content

If you want to work on the object after initialising it.

---

<div class="post-metadata">

**Author:** ![AurSSSSlien\_Bottazi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@AurSSSSlien\_Bottazi](https://www.ruby-forum.com/u/AurSSSSlien_Bottazi)\
**Post date:** [January 9, 2007, 8:12pm UTC](https://www.ruby-forum.com/t/form-and-symbol/81521/3 "2007-01-09T20:12:29Z")

</div>

Another thing I just spotted is your use of created\_at here…

> Created at  
> \<%= datetime\_select 'page', 'created\_at' %\>

created\_at is automatically set by rails when the @page object is  
created. updated\_at, its companion, keeps track of when the object was  
last saved after modification.

Gustav P.

---

<div class="post-metadata">

**Author:** ![AurSSSSlien\_Bottazi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@AurSSSSlien\_Bottazi](https://www.ruby-forum.com/u/AurSSSSlien_Bottazi)\
**Post date:** [January 9, 2007, 8:21pm UTC](https://www.ruby-forum.com/t/form-and-symbol/81521/4 "2007-01-09T20:21:31Z")

</div>

Woops!

params isn’t necessarily a hash of hashes, the insertwidget\_tag helpers  
for instance aren’t mapped that way…

\<%=text\_field\_tag :name%\>

will get passed to the controller as:  
params[:name]

Ciao  
Gustav P.

---

<div class="post-metadata">

**Author:** ![AurSSSSlien\_Bottazi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@AurSSSSlien\_Bottazi](https://www.ruby-forum.com/u/AurSSSSlien_Bottazi)\
**Post date:** [January 9, 2007, 8:13pm UTC](https://www.ruby-forum.com/t/form-and-symbol/81521/5 "2007-01-09T20:13:29Z")

</div>

Aurélien Bottazini wrote:

> and in the controller I use
> 
> Any idea?
> 
> >

Hey

The params hash is a hash of hashes… ie

irb(main):010:0\> params = {:page =\> {:foo =\> “bar”}}  
=\> {:page=\>{:foo=\>“bar”}}  
irb(main):011:0\> params[:page][:foo]  
=\> “bar”  
irb(main):012:0\> params[:page][:foo] = “diff”  
=\> “diff”  
irb(main):013:0\> params[:page][:foo]  
=\> “diff”

So in your example you could say:  
…  
params[:page][:title] = “Auto Title”  
@page = Page.new(params[:page])  
…

Goodluck,  
Gustav P.

---

<div class="post-metadata">

**Author:** ![AurSSSSlien\_Bottazi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@AurSSSSlien\_Bottazi](https://www.ruby-forum.com/u/AurSSSSlien_Bottazi)\
**Post date:** [January 9, 2007, 9:51pm UTC](https://www.ruby-forum.com/t/form-and-symbol/81521/6 "2007-01-09T21:51:47Z")

</div>

Thank you to both of you.

It works perfectly now.

> Another thing I just spotted is your use of created\_at here…
> 
> > Created at  
> > \<%= datetime\_select 'page', 'created\_at' %\>
> 
> created\_at is automatically set by rails when the @page object is  
> created. updated\_at, its companion, keeps track of when the object was  
> last saved after modification.
> 
> Gustav P.

I used scaffold to generate the code initially. But your right  
created\_at is automatically set by rails.

I am going to remove it from the form 😉

---

<div class="post-metadata">

**Author:** ![AurSSSSlien\_Bottazi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@AurSSSSlien\_Bottazi](https://www.ruby-forum.com/u/AurSSSSlien_Bottazi)\
**Post date:** [January 9, 2007, 9:23pm UTC](https://www.ruby-forum.com/t/form-and-symbol/81521/7 "2007-01-09T21:23:39Z")

</div>

Hi AurÃ©lien,

> It works but I need to modify the parameters I am sending to Page.new()
> 
> I know I can’t modify :page as it is a Symbol.  
> But how can I access the values contained inside :page?

title = params[:page][:title]  
content = params[:page][:content]

and so on…

– Jean-FranÃ§ois.

–  
Ã€ la renverse.
