jqueryajaxの投稿は404NotFound in Firebugを返します...何か足りないものはありますか?
編集:これは以前は機能していましたが、突然動作を停止しました routes.rb
#invites
match '/invites/request' => 'invites#request_invite'
invokes_controller.rb
class InvitesController < ApplicationController
def request_invite
if !request.xhr?
render_404
return
end
email_exists = Invite.where(:email => params[:invite][:email]).exists?
if email_exists
@return = { :error => false, :response => "<div class=\"success\">Thank you!</div>" }
else
@invitation = Invite.new(params[:invite])
if @invitation.save
@return = { :error => false, :response => "<div class=\"success\">Thank you!</div>" }
else
error_message = '<div class="error_message">' + @invitation.errors.full_messages.map {|error| "<p>#{error}</p>"}.join + "</div>"
@return = { :error => true, :response => error_message }
end
end
render :json => ActiveSupport::JSON.encode( @return )
end
end
招待.rb
class Invite < ActiveRecord::Base
validates :email, :presence => true, :uniqueness => true
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
end
javascript:
//post ajax
jQuery.fn.postAjax = function(success_callback) {
this.submit(function() {
$.post(this.action, $(this).serialize(), success_callback);
return false;
})
return this;
};
$(document).ready(function() {
$("#invites_form").postAjax(function(data){
if(data.error == true){
popup.init({
title : "Please fix the following errors:",
body : data.response
});
}
});
});