【发布时间】:2014-01-10 15:48:10
【问题描述】:
成功后,表单远程提交并正确加载 index.js.erb(生活很好)
但是在错误(其他)时没有任何反应。我想要做的是,在出错时加载不同的文件或向 index.js.erb 添加逻辑。但是,它只是失败并且无法加载。
错误 加载资源失败:服务器响应状态为 500(内部服务器错误)我知道在实施救援后收到 406 错误
(我知道这是因为它没有找到事件,但我如何确保它加载我的 index.js.erb- 所以我可以依次显示通知用户的模式)
事件控制器
def index
respond_to do |format|
if @event = Event.find_by_event_code(params[:checkin])
format.html { redirect_to @event, success: "You have found your event" }
format.js
elsif @event = Event.find_by_speaker_code(params[:checkin])
format.html { redirect_to @event, success: "Welcome Super User. You have found your event" }
format.js
else
format.html { redirect_to @event, error: "No event by that event code" }
format.js
end
end
end
index.js.erb
$("#checkin-popup").remove();
$("#checkin-confirm-popup").html("<%= escape_javascript(render("/events/index.html.erb")) %>")
$('#checkin-confirm-popup').modal('show');
button.html
<%= simple_form_for @event, remote: true ,:method => 'get' do |e| %>
<div class="talknumber"><%= text_field_tag :checkin, params[:search] %></div>
<%= e.button :submit, "Checkin", :class => "btn btn-default" %>
<% end %>
服务器日志
Started GET "/events?utf8=%E2%9C%93&checkin=1212122&commit=Checkin" for 127.0.0.1 at 2014-01-10 11:43:39 -0500
Processing by EventsController#index as JS
Parameters: {"utf8"=>"✓", "checkin"=>"1212122", "commit"=>"Checkin"}
(0.5ms) SELECT "users"."name" FROM "users"
Event Load (0.5ms) SELECT "events".* FROM "events" WHERE "events"."event_code" = 1212122 ORDER BY events.created_at ASC LIMIT 1
Event Load (0.4ms) SELECT "events".* FROM "events" WHERE "events"."speaker_code" = 1212122 ORDER BY events.created_at ASC LIMIT 1
Completed 406 Not Acceptable in 7ms (ActiveRecord: 1.4ms)
【问题讨论】:
标签: javascript jquery ruby-on-rails redirect