2013-10-08 38 views
0

我想要一个表单提交(POST),在我的控制器中执行评估(基于表单中的数据)的自定义操作,然后弹出一个jQuery模型,具有该评估的结果。诀窍是,我希望这种模式能够弹出窗体,以便如果他们关闭模式,他们可以返回并查看/编辑窗体。Rails表单提交到控制器动作和jQuery模态

我试过类似下面的东西,但它不起作用。我得到以下错误:

缺少模板游戏/评估,应用程序/评估{:locale => [:en],::formats => [:html],:handlers => [:erb,:builder ,:raw,:ruby,:coffee,:haml]}。

/app/controllers/games_controller.rb

class ExercisesController < ApplicationController 
    #...  
    def evaluate 
    if(params[:id]) 
     found = Game.find(params[:id]) 
     @eval = found.evaluate_guess(params[:guess]) 
    end 
    end 
    #... 
end 

/app/views/games/play.html.haml

= semantic_form_for @games, :url => evaluate_path(@games) do |f| 
    = f.semantic_errors 
    = f.input :guess, 
    :as => :text 
= f.actions do 
    = f.action :submit, :label => "Guess!", 
    :button_html => { :action => :evaluate, :method => :post } 

/应用/视图/游戏/_evaluation_modal.html.haml

#evaluation_modal.modal.modal-wide.hide.fade 
    = semantic_form_for @exercise, html: { class: 'modal-form' } do |f| 
    .modal-header 
    %h3 Results 

    .modal-body 
     #flashbar-placeholder 
     %h2= CGI.unescapeHTML(@eval).html_safe 

/app/views/games/evaluate.js.coffee

$('#evaluate').html(
    '<%= escape_javascript render partial: "evaluation_modal" %>') 
$('#evaluation_modal').modal('show') 

/config/routes.rb

#... 
get '/play/:id' => 'games#play', as: :play 
patch '/play/:id' => 'games#evaluate', as: :evaluate 
#... 

回答

0

尝试增加:remote => trueplay形式。

= semantic_form_for @games, :url => evaluate_path(@games), :remote => true do |f|