2012-12-12 54 views
0

我有這個問題,此嵌套形式,當涉及到顯示問題(q_text)和唯一的黑客香港專業教育學院發現是使用text_area,然後它的形式顯示標籤的對象

<%= f.fields_for :answered_questions do |a| %> 
    <%= a.check_box :answer %> 
    <%= a.text_field :q_text %> 
<% end %> 

這裏是如何這看起來:http://postimage.org/image/azrbgidht/

,但我不希望使用text_field - 因爲它的輸入,但沒有表現出像我想

如果我行更改爲<%= a.label :q_text %>文本我得到這樣的:http://postimage.org/image/l4pz62w29/

如何讓表單對象理解標籤應該是問題文本(q_text)而不僅僅是q_text

UPDATE

我改變了代碼,使用simple_form但現在的標籤在所有

<%= simple_form_for(@test_session) do |f| %> 

    <%= f.fields_for :answered_questions do |ff| %> 

    <%= ff.check_box :answer, :label => ff.object.q_text %> 

    <% end %> 
<% end %> 
+0

你可以有一個標籤和一個text_field。 –

+0

我真的不想text_field,但只是一個標籤,check_box處理輸入 – Matti

回答

0

dosnt顯示這是我的固定它,顯然我不能使用內嵌標籤和同時形成物體

<%= f.simple_fields_for :answered_questions do |ff| %>

<%= ff.check_box :answer %>

<%= ff.label ff.object.q_text %>

<% end %>

0
Write as following. 

<%= a.label :q_text,"questions text" %> 
+0

我不想在這裏設置':q_text'屬性,但從':回答_questions'模型獲得它的值 – Matti

+0

是的,你可以。 <%= a.label「#{您的對象來自answers_questions}」%>可能有效。 – VenkatK

+0

即時通訊不知道如何做這個權利,但如果我有'<%= a.label「#{a.q_text}」%>'我得到未定義的方法'q_text'爲嵌套形式 – Matti