[英]Rails form submit to controller action and jQuery modal
我希望表單提交(POST)該控制器中的自定義操作,該操作將執行評估(基於表單中的數據),然后彈出具有該評估結果的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 }
/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
#...
嘗試在play
表單中添加:remote => true
。
= semantic_form_for @games, :url => evaluate_path(@games), :remote => true do |f|
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.