# About the form\_for

**URL:** <https://www.ruby-forum.com/t/about-the-form-for/134002>\
**Category:** Rails\
**Created:** [April 6, 2008, 1:09pm UTC](https://www.ruby-forum.com/t/about-the-form-for/134002 "2008-04-06T13:09:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent.Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@Vincent.Z](https://www.ruby-forum.com/u/Vincent.Z)\
**Post date:** [April 6, 2008, 1:09pm UTC](https://www.ruby-forum.com/t/about-the-form-for/134002/1 "2008-04-06T13:09:09Z")

</div>

question one:

is there any select box tag for form\_for?

now,perhaps i just can use the select or select\_tag?

question tow:

i have a A model,it has one B such as:

class A\< ActiveRecord::Base  
belongs\_to :B

when i use the form\_for tag,how can i output the variable name?like  
this:

\<%form\_for :a,@a,:url=\>{:controller=\>“a”,:action=\>“save”} do |f|%\>  
\<%=f.text\_area “b[name]”%\>  
…  
\<%end%\>

it doesnt work.

thanks for your help!

---

<div class="post-metadata">

**Author:** ![Vincent.Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@Vincent.Z](https://www.ruby-forum.com/u/Vincent.Z)\
**Post date:** [April 6, 2008, 2:41pm UTC](https://www.ruby-forum.com/t/about-the-form-for/134002/2 "2008-04-06T14:41:51Z")

</div>

[http://api.rubyonrails.org/](http://api.rubyonrails.org/) is the best resource for queries like  
these. The answer to your question is a yes, just browse through the  
documentation to figure it out.

---

<div class="post-metadata">

**Author:** ![Vincent.Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@Vincent.Z](https://www.ruby-forum.com/u/Vincent.Z)\
**Post date:** [April 6, 2008, 4:23pm UTC](https://www.ruby-forum.com/t/about-the-form-for/134002/3 "2008-04-06T16:23:25Z")

</div>

hi,i have the api source,and i have searched it.i have not found the  
solution.

pls show me some details,thanks for your help.

---

<div class="post-metadata">

**Author:** ![Vincent.Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@Vincent.Z](https://www.ruby-forum.com/u/Vincent.Z)\
**Post date:** [April 6, 2008, 4:44pm UTC](https://www.ruby-forum.com/t/about-the-form-for/134002/4 "2008-04-06T16:44:36Z")

</div>

thanks! 🙂

On Apr 6, 10:25 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Vincent.Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@Vincent.Z](https://www.ruby-forum.com/u/Vincent.Z)\
**Post date:** [April 6, 2008, 5:02pm UTC](https://www.ruby-forum.com/t/about-the-form-for/134002/5 "2008-04-06T17:02:49Z")

</div>

i wanna set up a blank text area for b.name,i dont wanna display  
something.

when i code :

\<%fields\_for :b,@a.b do |b|%\>

there is one error as follows:

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.b

On Apr 6, 10:25 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Vincent.Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@Vincent.Z](https://www.ruby-forum.com/u/Vincent.Z)\
**Post date:** [April 7, 2008, 2:54pm UTC](https://www.ruby-forum.com/t/about-the-form-for/134002/6 "2008-04-07T14:54:44Z")

</div>

Does anyone have encountered the problem?

---

<div class="post-metadata">

**Author:** ![Vincent.Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@Vincent.Z](https://www.ruby-forum.com/u/Vincent.Z)\
**Post date:** [April 6, 2008, 4:26pm UTC](https://www.ruby-forum.com/t/about-the-form-for/134002/7 "2008-04-06T16:26:57Z")

</div>

On 6 Apr 2008, at 12:08, Vincent.Z wrote:

> question one:
> 
> is there any select box tag for form\_for?

Like f.select (assuming f is your form builder?)

> belongs\_to :B
> 
> when i use the form\_for tag,how can i output the variable name?like  
> this:
> 
> \<%form\_for :a,@a,:url=\>{:controller=\>“a”,:action=\>“save”} do |f|%\>  
> \<%=f.text\_area “b[name]”%\>  
> …  
> \<%end%\>

You’re trying to display a.b.name ? If so you could either drop down a  
level and use text\_area\_tag, or use fields\_for to create a scope  
around b (and then you can just do other\_f.text\_area :name)

Fred

---

<div class="post-metadata">

**Author:** ![Vincent.Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@Vincent.Z](https://www.ruby-forum.com/u/Vincent.Z)\
**Post date:** [April 7, 2008, 9:05pm UTC](https://www.ruby-forum.com/t/about-the-form-for/134002/8 "2008-04-07T21:05:11Z")

</div>

Your @a variable is nil. Make sure that you’re setting it.

Also, I’m not sure if it would mess anything up or not, but naming the  
param :b and setting the block variable to |b| might get confusing.  
Perhaps you should use something else in the block.

-Kyle

---

<div class="post-metadata">

**Author:** ![Vincent.Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@Vincent.Z](https://www.ruby-forum.com/u/Vincent.Z)\
**Post date:** [April 7, 2008, 7:23pm UTC](https://www.ruby-forum.com/t/about-the-form-for/134002/9 "2008-04-07T19:23:51Z")

</div>

This is not a helpful response whatsoever. People don’t come to post  
in Google G. to get pointed to documentation.

---

<div class="post-metadata">

**Author:** ![Vincent.Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@Vincent.Z](https://www.ruby-forum.com/u/Vincent.Z)\
**Post date:** [April 8, 2008, 1:09am UTC](https://www.ruby-forum.com/t/about-the-form-for/134002/10 "2008-04-08T01:09:45Z")

</div>

Matthew C. wrote:

> This is not a helpful response whatsoever. People don’t come to post  
> in Google G. to get pointed to documentation.

Repeating all that info would degrade this forum. When a newb obviously  
does not  
know about the /Agile Web/ book, or the online APIs, or how to Google  
for our  
common FAQs, they need a meta-answer.

–  
Phlip

---

<div class="post-metadata">

**Author:** ![Vincent.Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@Vincent.Z](https://www.ruby-forum.com/u/Vincent.Z)\
**Post date:** [April 9, 2008, 3:41pm UTC](https://www.ruby-forum.com/t/about-the-form-for/134002/11 "2008-04-09T15:41:04Z")

</div>

@vincent – I like the api at [railsbrain.com](http://railsbrain.com) It’s the same api info,  
just has a little ajax added to it making it easier to search.
