Rails Javascript重定向在移动与桌面时的行为有所不同

时间:2015-02-07 17:53:09

标签: javascript ruby-on-rails

以下是我认为产生问题的控制器代码。在桌面和移动视图中,唯一的区别似乎在"渲染"部分控制器代码。

if params[:option] == "takequiz" 
  @lang = @lang + 1
  current_user.bookmark = @lang
  current_user.quiz_flag = 1
  current_user.save
  render :js => "window.location = '/langs'"
end

在桌面视图中,它将show动作呈现为JS,如下所示:

enter image description here

并按预期生成以下网址:

enter image description here

在移动视图中,它将show动作呈现为HTML,如下所示:

enter image description here

并生成以下不会重定向的网址:

enter image description here

有关为什么会出现这种情况的任何想法?我使用的是JQuery Mobile,并使用Railscast第199集中提出的想法设置了我网站的移动部分。

1 个答案:

答案 0 :(得分:1)

尝试将重定向作为ajax回调而不是使用render。

添加:remote =>如果是link_to标记

,则为true