mtcrts70
mtcrts70

Reputation: 35

Rails Javascript redirect behaves differently when in mobile vs desktop

Here is the piece of controller code I think is producing the issue. In both desktop and mobile view the only difference appears to be in the "render" portion of the controller code.

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

When in desktop view it renders the show action as JS as shown below:

enter image description here

And produces the following URL as expected:

enter image description here

When in mobile view it renders the show action as HTML as shown below:

enter image description here

And produces the following URL which doesn't redirect:

enter image description here

Any thoughts as to why this might be? I'm using JQuery Mobile and have set up the mobile portion of my website using the ideas presented in Railscast episode 199.

Upvotes: 0

Views: 53

Answers (1)

Andrew Hendrie
Andrew Hendrie

Reputation: 6415

Try doing the redirect as an ajax callback instead of using render.

Add :remote => true to the link_to tag

Upvotes: 1

Related Questions