JavaScript Rails server returning HTML as opposed to JavaScript

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 true, my expectation was that the server would naturally try to return JavaScript with the AJAX response.

However, each time the link is clicked the AJAX response contains HTML from a file called users/friends.html.erb rather than JavaScript that dynamically renders the HTML from users/_friends.html.erb which would be the required behaviour.

My code for handling the request is as follows:

--Route:

# config/routes.rb

get '/index_friends' => 'users#friends'

--Action:

# app/controllers/users_controller.rb

def friends
  ...

  respond_to do |format|
    format.js
    format.html
  end
end

--js.erb template:

# 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
Answer:1

Try

"data-type" => "js"

after

remote: true
Answer:2

I'm having troubles with REGEX trying to build one that would retrieve the first letter of a word and any other Capital letter of that word and each first letter including the any Capital letter in ...

I'm having troubles with REGEX trying to build one that would retrieve the first letter of a word and any other Capital letter of that word and each first letter including the any Capital letter in ...

So I'm developing a website for a friend of mine and have encountered an issue with the file upload field within a form. The form consists of several text inputs and the file field itself. Variables ...

So I'm developing a website for a friend of mine and have encountered an issue with the file upload field within a form. The form consists of several text inputs and the file field itself. Variables ...

  1. check file upload size in javascript
  2. check file upload in postman
  3. check file upload is empty in php
  4. check file upload in jquery
  5. check file upload extension in c#
  6. check file upload size in php
  7. check file upload php
  8. check file upload type in jquery
  9. check file upload error php
  10. check file upload size in jquery
  11. check file upload validation in jquery
  12. check file upload error in codeigniter
  13. check file upload empty javascript
  14. check file upload in javascript
  15. check file upload codeigniter
  16. check file upload laravel
  17. check file upload size c#
  18. check file upload
  19. check file upload value in jquery
  20. check file upload type javascript

in a $.each() I do a AJAX-request: $.each(all, function(i,v) { $.ajax({ url: "/mycontroller/"+encodeURIComponent(v), success: function(data){ ...

in a $.each() I do a AJAX-request: $.each(all, function(i,v) { $.ajax({ url: "/mycontroller/"+encodeURIComponent(v), success: function(data){ ...

I have a modal form using bootstrap. The form contains some text inputs and a image input. I submit the form with ajax, and all data is received at the PHP file correctly. Alas, the image isn't ...

I have a modal form using bootstrap. The form contains some text inputs and a image input. I submit the form with ajax, and all data is received at the PHP file correctly. Alas, the image isn't ...

  1. submit form with javascript
  2. submit form with jquery
  3. submit form with ajax
  4. submit form with button
  5. submit form with link
  6. submit form with anchor
  7. submit form with a tag
  8. submit form with button outside form
  9. submit form with enter key
  10. submit form with get method
  11. submit form with php
  12. submit form with react
  13. submit form with input type button
  14. submit form with fetch
  15. submit form with curl
  16. submit form with selenium python
  17. submit form with enter key react
  18. submit form with value javascript
  19. submit form with multiple inputs
  20. submit form with python requests