I want a form to submit (POST) that a custom action in my controller that will perform an evaluation (based on the data from the form) and then pop up a jQuery model that has the results of that evaluation. The trick is, I want this modal to just pop over the form so that if they close the modal, they can go back and see/edit the form.
I've tried something like the following, but it does not work. I get the following error:
Missing template games/evaluate, application/evaluate with {: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|
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.