コースが選択されたときに、アクションを使用してコースのすべてのトピックを表示しました。number_question
ここで、仮想属性を使用して、使用するトピックごとにフォームにフィールドを表示し、数値を入力できるようにしたいと考えています。私のモデル:
class GeneralExam < ActiveRecord::Base
attr_accessible :course_id, :description
attr_accessor :numbe_question
end
これは私のフォームです:
<%= simple_form_for @general_exam, defaults: { error: false } do |f| %>
<fieldset>
<legend>General Exam information</legend>
<%= render 'shared/error_messages', object: f.object %>
<%= f.association :course, collection: current_user.courses, prompt: "Choose Course for exam" %>
<%= f.input :name %>
<%= f.input :description, input_html: { rows: 2, class: 'span6' } %>
</fieldset>
<fieldset>
<legend>Choose number question for topics</legend>
<div id="list_topics">
</div>
</fieldset>
<%= f.submit class: "new_resource" %>
<% end %>
これは私の行動です:
def update_topics
@course = Course.find(params[:course_id])
@topics = @course.topics
end
じぶんのupdate_topics.js.erb
$('#list_topics').html("<%= j (render('general_exams/list_topics')) %>")
私の_list_topics.html.erb
部分:
<% @topics.each do |topic| %>
<h5><%= topic.name %></h3>
<%# f.input :number_question, input_html: { name: "number_question[#{topic.id}]" } %>
<% end %>
しかし、入力フィールドを表示したい場合はf
オブジェクトが必要ですが、レンダリングするとオブジェクトが_list_topics
ありませんでした。f
フォームのオブジェクトをパーシャルに渡す方法を知りたい_list_topics
ですか?
または、jquery を使用してフォームの要素の後に入力フィールドを追加する方法を誰かが教えてくれますh5
。どうもありがとうございました。