From d6e3dc95c99f8e8588033b15d74dc8c57a58fde3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Rodr=C3=ADguez-Baltan=C3=A1s=20D=C3=ADaz?= Date: Fri, 9 Mar 2012 18:47:55 +0100 Subject: [PATCH] Add redirect_to(url) helper --- lib/apotomo/widget/javascript_methods.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/apotomo/widget/javascript_methods.rb b/lib/apotomo/widget/javascript_methods.rb index 45976b0..5a50486 100644 --- a/lib/apotomo/widget/javascript_methods.rb +++ b/lib/apotomo/widget/javascript_methods.rb @@ -35,6 +35,16 @@ def update(*args) wrap_in_javascript_for(:update, *args) end + # Instruct the browser to perform a redirect to the specified url. + # + # Example: + # + # redirect_to course_path(@course.id) + # #=> "window.location.replace(\"davinci.dev/courses/4f592ee4b5a482327b000008\");" + def redirect_to(url) + render :text => "window.location.replace(\"#{url}\");" + end + private def wrap_in_javascript_for(mode, *args) selector = args.first.is_a?(String) ? args.shift : false