我正在使用Rails4和Zurb Foundation框架,并试图做一个简单的测验。您可以从课程页面启动测验。Foundation提供了一种从一个模式移动到另一个模式(每个模式都链接到下一个模式)的方法,我对此非常了解,但我的模式要复杂一些,因为我在每个模式上都有一个表单,并且需要在加载下一个模式之前通过我的LessonsController 'check‘操作路由用户输入。所以我不会重定向到另一个页面。我只需要激活链接,如果答案是正确的,就会弹出下一个模式。
以下是从课程页面启动的第一个模式:
<div id="lesson1Modal" class="reveal-modal" data-reveal>
<div class="row">
<%= form_tag url_for(:controller => 'lessons', :action => 'check'), method: :get do %>
<div class="small-4 columns">
<%= @lesson.problems.first.content %>
</div>
<div class="small-8 columns">
<%= text_field_tag :guess %>
</div>
<%= hidden_field_tag :lesson_id, @lesson.id %>
<%= submit_tag "Check your answer!", class: 'button tiny' %>
<% end %>
</div>
</div>这是我的LessonsController
class LessonsController < ApplicationController
def show
@lesson = Lesson.find(params[:id])
end
def check
@lesson = Lesson.find(params[:lesson_id])
@user = current_user
if params[:guess] == @lesson.problems.first.answer
# here I need an equivalent for what Zurb's button for launching a second modal from the
# first: # <a href="#" data-reveal-id="one-2" class="secondary button">Continue</a>
else
# retry the problem
end
end
end因此,我需要控制器调出带有data-data id=“one-2”的模型。有人能帮上忙吗?提前感谢!
发布于 2014-05-09 04:03:39
创建文件:check.js.erb
if (<%= @variable_set_in_controller %>){
$(".close-reveal-modal").click();
$("#LinkTo2ndModal").click(); //Or use foundation's js to call it programmatically
}else{
alert("Wrong!");
}这应该由控制器自动触发,因为没有要重定向到的check.html.erb。
https://stackoverflow.com/questions/23551120
复制相似问题