markhorrocks
markhorrocks

Reputation: 1398

rails jquery mobile redirects to wrong url

In a rails 4 jQuery mobile application, after updating a record, my controller redirects to the index (list) page but the browser url is show while the view is index.

I think the answer is to turn off Ajax but I can't figure out how to incorporate the jQuery mobile directive data-ajax="false" into the rails form helper.

<%= form_for (@user) do |f| %>

browser:

http://localhost:3000/users/1

view in browser :index.html.erb

routes.rb:

resources :users

controller:

def update
  respond_to do |format|
    if @user.update(user_params)
      format.html { redirect_to users_path,
                  notice: "User #{@user.user_name} was successfully updated." }
    else
      format.html { render action: 'edit' }
    end
  end
end

Upvotes: 0

Views: 338

Answers (2)

Lane
Lane

Reputation: 4986

That works well by @markhorrocks answer. And my solution is like you. Just add a instance variable in controller, like @data_url = '/room', and add ruby <div data-role="page" id="home" data-url="<%= @data_url %>">

Upvotes: 0

markhorrocks
markhorrocks

Reputation: 1398

The solution is to add the data-url directive into my layout.

<div data-role="page" id="home" data-url="<%= request.path %>">

Upvotes: 1

Related Questions