Facebookのすべての連絡先をインポートするレールアプリがあります。これには時間がかかります。私は「待ってください」ページを表示したいのですが、インポートが背中で起こっている間は、レイルズ "お待ちください"ページ
レンダリングとredirect_toをコントローラの同じアクションに置くことはできないようです。これどうやってするの?
if @not_first_time
Authentication.delay.update_contact_list(current_user)
else
render 'some page telling the user to wait'
Authentication.import_contact_list(current_user)
end
redirect_to :root_path, :notice => 'Succesfully logged in'
それは、サイトのユーザーは初めてであれば、私は、「ページをお待ちください」インポートを開始し、そのが行われた後は、このデータを処理大量のルートパスにリダイレクトレンダリングしたいですそれが初めてではない場合
起こり、その後、(delayed_jobs宝石を使用して)バックグラウンドで接触更新を入れて、私は連絡先をインポートするfb_graphの宝石を使用しているホーム・ページ
に直行。ここで私はそれが動作しますが、解決策は、以下の提案を追加する方法
def self.import_contact_list(user)
user.facebook.friends.each do |contact|
contact_hash = { 'provider' => 'facebook', 'uid' => contact.identifier, 'name' => contact.name, 'image' => contact.picture(size='large') }
unless new_contact = Authentication.find_from_hash(contact_hash)
##create the new contact
new_contact = Authentication.create_contact_from_hash(contact_hash)
end
unless relationship = Relationship.find_from_hash(user, new_contact)
#create the relationship if it is inexistent
relationship = Relationship.create_from_hash(user, new_contact)
end
end
エンド
編集
です!
ここだが
<script>
jQuery(document).ready(function() {
$.get("/import_contacts", function(data) {
window.location.replace("/")
});
});
</script>
<% title 'importing your contacts' %>
<h1>Please wait while we import your contacts</h1>
<%= image_tag('images/saving.gif') %>
感謝を「待つ」アクションからビュー「私たちは連絡先のインポートながら待つ」を私のです!
あなたはajaxの使用について考えましたか?おそらく、これははるかに簡単でより流動的なsoltionになります。 – alex
AJAXはあなたのためのソリューションです。 jQueryを使用している場合は、このhttp://api.jquery.com/jQuery.get/をご覧ください。 AJAX get in jQueryはリクエストが返ったときに実行されるコールバック関数を提供します(あなたの場合は連絡先がインポートされます)。リクエストが返された後、あなたはどんなメッセージを表示することもできます(あなたのケースでは "成功してログインしました") – mohamagdy
私はAjaxの使用を考えました。しかし、私は[fb_graph gem](https://github.com/nov/fb_graph)を使用してインポートしています。私は宝石のコードに侵入したくありません... – wachichornia