我正在创建表格列表说
Questions form
Answers form
Hints form
所有这些都有不同的控制器和视图,question_controller、answers_controller、hints_controller。
现在我需要在主页的选项卡式 UI 中获取所有这些视图(比如 home_controller , home#index)
我尝试了render : partial ,render :template也与locals,我无法实现。
可以通过将所有对象移动到同一个控制器(home_controller,但我不确定这种方法,因为它会使家庭控制器过于复杂而无法管理)来轻松完成,但我需要将它保存在单独的控制器中(question_controller,answers_controller , hints_controller) 并将其呈现到同一页面。我正在使用客户端验证,简单的表单宝石。
下面是我的问题控制器
class QuestionsController < ApplicationController
def index
@question = Question.new
@question_status = []
@question_mode = []
@question_type = []
@question_lookups = Lookup.where({:lookup_for => "question"})
@question_lookups.each do |lk|
case lk.lookup_type
when 'mode'
@question_mode << lk
when 'status'
@question_status << lk
else
@question_type << lk
end
end
@caa = Questioncaa.new
end
end
问题视图(简单形式)
<%= simple_form_for @question, :validate => true do |q| %>
<%= q.input :question_info, :as => :ckeditor, :input_html => { :toolbar => 'Easy', :width => 750 } %>
<%= q.input :question_source %>
<%= q.input :is_mobile %>
<%= q.input :is_similar_question %>
<%= q.input :is_boss_question %>
<%= q.input :is_racing_question %>
<%= q.input :is_speed_question %>
<%= q.input :difficulty_level %>
<%= q.input :ideal_time %>
<%= q.input :lookups, :collection => @question_mode, :value_method => :id, :label_method => :lookup_value,:prompt => "Choose Mode", :label => :QuestionMode %>
<%= q.input :lookups, :collection => @question_status, :value_method => :id, :label_method => :lookup_value,:prompt => "Choose Status", :label => :QuestionStatus %>
<%= q.input :lookups, :collection => @question_type, :value_method => :id, :label_method => :lookup_value,:prompt => "Choose Type", :label => :QuestionType %>
<%= simple_fields_for @caa do |c| %>
<%= c.input :needs_hints %>
<%= c.input :needs_video_solution %>
<%= c.input :needs_tips_tricks %>
<%= c.input :needs_formulae %>
<%= c.input :needs_key_concepts %>
<% end %>
<%= q.button :submit %>
<% end %>
主页视图
<div class="tab-content">
<div class="tab-pane active" id="learning_map">
<!-- I need to acheive this -->
<%= render :template => "learning_map/index" %>
</div>
<div class="tab-pane" id="questions">
<!-- I need to acheive this -->
<%= render :template => "questions/index", :collection => @question_mode %>
</div>
<div class="tab-pane" id="answers">.
<!-- I need to acheive this -->
<%= render :templates => "answers/index" %>
</div>
</div>
请给我建议,这将非常有帮助。感谢您阅读本文。