我有两个名为quiz
和question
quiz has_many questions
我想在quiz
新form_for
添加参数,因此我可以在quizs_controller
中使用它们。例如from
和to
,用户可以输入整数来获取from xx to xx
范围内的问题。
但我不想在from
模型中添加to
和quiz
参数。
我想知道如何实现这一点。
感谢。
修改
测验/ new.html.erb
<%= form_for [:admin, @quiz] do |f| %>
<div class="form-group">
<%= f.label :title, "Title:" %>
<%= f.text_field :title, :class => "form-control" %>
</div>
<div class="form-group">
<%= f.label "Range:" %>
<!-- I want to know how to add `from` and `to` params here -->
</div>
<%= f.submit "Submit", data: { disable_with: "Submitting..." }, class: "btn btn-primary" %>
<%= link_to "Cancel", admin_quizzes_path %>
<% end %>
quizzes_controller.rb
def new
@quiz = Quiz.new
end
def create
@quiz = Quiz.new(quiz_params)
@questions = @quiz.questions
# And I want to gain the `from` and `to` here to **FILTER** THE questions
if @quiz.save
redirect_to admin_quizzes_path
else
render :new
end
end
答案 0 :(得分:0)
在表单内添加:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img class = "<?php echo $i ?>" src="" alt="" height="22" width="30">
<br/>
<label> AD Mgr </label>
<br/>
<select class="acc">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<div class="form-group">
<%= label_for :from %>
<%= number_field_tag :from, :class => "form-control" %>
</div>
相同。
在您的控制器中,您可以将它们引用为:
to
这对你有用吗?