バックボーンを使用する Rails アプリがありますが、save を呼び出すと、既にログインしているにもかかわらず、サーバーがログインにリダイレクトされます (バックボーン モデルが見つかったページは、ログイン後にのみ表示されます)。
ネストされたモデルに backbone.matroyshka を使用していますが、削除しても問題は解決しません。
ビュー内のモデルで save を呼び出すコードは次のとおりです。
var view = this;
// save model
this.model.save(null, {
success: function(model, response) {
view.$('#saving').hide();
view.notice('Saved!', 'success');
},
error: function(model, response) {
view.$('#saving').hide();
view.notice(response, 'error');
console.log('save failed ' + response, view.model.get('url'));
}
});
model.save リクエストの前に、jQuery AJAX を使用してデータを取得する AJAX リクエストがあります。
$.ajax({
type: 'GET',
url: serverUrl,
data: { url: model.get('url') },
dataType: "json",
context: this,
success: function(data) {
model.set(data);
},
error: function(xhr, status, error) {
console.log('lookup share url failed ' + error, this.get('source'), this.get('about'));
this.trigger('load:fail');
if (options.error) {
options.error(this, error);
}
}
});
model.save はサーバーから 302 found を受け取り、ログイン ページにリダイレクトします。リソースのコントローラは、によって保護されています
before_filter :signed_in_user, only: [:create]
signed_in_user は、omni_auth の使用に関するチュートリアルから直接取得したセッション ヘルパーにあります。
def signed_in_user
unless signed_in?
store_location
redirect_to login_path, notice: "You must be logged in to find out what they do."
end
終わり
AJAX(バックボーンではない)で保存する別のページがあり、正常に動作します(サインインしたユーザーも必要です)。