I have the following link_to helper:
# app/views/users/show.html.erb <div id="social"> <%= link_to "Friends", index_friends_path, id: "index_friends", remote: true %> </div>
Since the value of
:remote is set to
However, each time the link is clicked the AJAX response contains HTML from a file called
users/_friends.html.erb which would be the required behaviour.
My code for handling the request is as follows:
# config/routes.rb get '/index_friends' => 'users#friends'
# app/controllers/users_controller.rb def friends ... respond_to do |format| format.js format.html end end
# app/views/friends.js.erb $("#social").html("<%= j(render("friends")) %>");
The corresponding Rails log entry looks like this:
# log/development.log Started GET "/index_friends" for 127.0.0.1 at 2015-09-13 12:20:41 +0100 Processing by UsersController#friends as JS
"data-type" => "js"