我想要一个表单来提交(POST)我的控制器中的一个自定义操作,该操作将执行评估(基于表单中的数据),然后弹出一个具有该评估结果的 jQuery 模型。诀窍是,我希望这个模态只是弹出表单,这样如果他们关闭模态,他们可以返回并查看/编辑表单。
我已经尝试过类似以下的方法,但它不起作用。我收到以下错误:
缺少模板游戏/评估,应用程序/评估与 {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :哈姆]}。
/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 }
/app/views/games/_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
#...