# Help needed in rails view

**URL:** <https://www.ruby-forum.com/t/help-needed-in-rails-view/143053>\
**Category:** Rails\
**Created:** [July 14, 2008, 8:52pm UTC](https://www.ruby-forum.com/t/help-needed-in-rails-view/143053 "2008-07-14T20:52:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mitkok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ebca7d/32.png) [@mitkok](https://www.ruby-forum.com/u/mitkok)\
**Post date:** [July 14, 2008, 8:52pm UTC](https://www.ruby-forum.com/t/help-needed-in-rails-view/143053/1 "2008-07-14T20:52:41Z")

</div>

Hi, guys.  
I’m new in Rails and now I’m playing around with it.  
I’m writing simple test system. The basic stuff is at  
[http://pastie.org/233197](http://pastie.org/233197)  
The thing is I don’t know how to get the answer and the suggestions and  
put them in html form with radio buttons.

Thanks in advance.  
Mitko K…

---

<div class="post-metadata">

**Author:** ![mitkok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ebca7d/32.png) [@mitkok](https://www.ruby-forum.com/u/mitkok)\
**Post date:** [July 14, 2008, 9:40pm UTC](https://www.ruby-forum.com/t/help-needed-in-rails-view/143053/2 "2008-07-14T21:40:50Z")

</div>

I find it easier to debug model relationships in the console as  
opposed to the browser… try (this is a guess as to your schema,  
change attributes as needed of course)

$ script/console  
…

> > q = Question.create :content=\>“where’s the beef?”, :user=\>“guest”  
> > =\> true  
> > q.answer = Answer.create :content=\>“in my belly”, :user=\>“fat bastard”  
> > =\> true  
> > q.suggestions  
> > =\> []  
> > q.suggestions \<\< Suggestion.create :content=\>“look in the fridge”  
> > =\> true

When accessing these resources you’ll probably want to only reference  
an answer within the context of it’s question. Your routes.rb file (in  
config) should include:

map.resources :questions, :has\_one =\> :answer\

I recommend you pick up ‘Advanced Rails Recipes’ and read Adam  
Wiggins’ recipe regarding nested resources. HTH.

SH

On Jul 14, 11:52 am, Mitko K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mitkok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ebca7d/32.png) [@mitkok](https://www.ruby-forum.com/u/mitkok)\
**Post date:** [July 14, 2008, 10:20pm UTC](https://www.ruby-forum.com/t/help-needed-in-rails-view/143053/3 "2008-07-14T22:20:59Z")

</div>

I know how to save the record, the problem is to generate the form.

---

<div class="post-metadata">

**Author:** ![mitkok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ebca7d/32.png) [@mitkok](https://www.ruby-forum.com/u/mitkok)\
**Post date:** [July 14, 2008, 11:31pm UTC](https://www.ruby-forum.com/t/help-needed-in-rails-view/143053/4 "2008-07-14T23:31:31Z")

</div>

Do you want to access the answer in the question form? Your pastie  
looks like a form\_for @question… Or do you want to create a form\_for  
@answer (scoped to it’s question)?

I don’t think I understand what the radio buttons should do either,  
can you explain more the form please? thx

On Jul 14, 1:20 pm, Mitko K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mitkok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ebca7d/32.png) [@mitkok](https://www.ruby-forum.com/u/mitkok)\
**Post date:** [July 15, 2008, 12:33am UTC](https://www.ruby-forum.com/t/help-needed-in-rails-view/143053/5 "2008-07-15T00:33:00Z")

</div>

I haven’t used radio buttons enough to know how to do this without  
playing with it … check out Softie’s on Rails “Absolute Moron’s  
Guide to Forms in Rails”  
[http://www.softiesonrails.com/2008/4/8/absolute-moron-s-guide-to-forms-in-rails-part-4](http://www.softiesonrails.com/2008/4/8/absolute-moron-s-guide-to-forms-in-rails-part-4).

Number 4 deals specifically with radio buttons and it should help  
you, I found all five to be helpful. You’ll probably want to randomize  
the order of your answer and suggestions so the answer isn’t always  
“C” or something… I’d be interested to see how you do that.

SH

On Jul 14, 2:41Â pm, Mitko K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mitkok](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ebca7d/32.png) [@mitkok](https://www.ruby-forum.com/u/mitkok)\
**Post date:** [July 14, 2008, 11:41pm UTC](https://www.ruby-forum.com/t/help-needed-in-rails-view/143053/6 "2008-07-14T23:41:02Z")

</div>

shenry wrote:

> Do you want to access the answer in the question form? Your pastie  
> looks like a form\_for @question… Or do you want to create a form\_for  
> @answer (scoped to it’s question)?
> 
> I don’t think I understand what the radio buttons should do either,  
> can you explain more the form please? thx
> 
> On Jul 14, 1:20ï¿½pm, Mitko K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> I’ve got questions tabel, answers table and suggestions table.  
> And when I want to make a test I want to get a question content, answer  
> and suggestions foru this question. Then I want to put the answer and  
> the suggestions into radio buttons :  
> [http://img135.imageshack.us/img135/4080/picture1zj9.png](http://img135.imageshack.us/img135/4080/picture1zj9.png)

Thanks.
