I need to make a call to a server-side controller method that will return a string, eventually formatted as JSON. Once I receive this data on the client side, I want to use it to update a specific part of the user interface.
Here is my current setup:
Controller:
class HomeController < ApplicationController
def index
end
def show
end
def name
name = "Sean"
respond_to do |format|
format.html
format.json {render json: name }
end
end
end
Routes:
resources :home do
collection do
get 'name'
end
end
AJAX Call:
window.callAPI = () ->
$.ajax
type: "GET"
url: "/home/name"
success: (data) ->
console.log data
error: (error) ->
console.log error
However, I am encountering the following error:
Started GET "/home/name" for 127.0.0.1 at 2015-01-22 13:28:59 -0700
Processing by HomeController#name as */*
Completed 500 Internal Server Error in 9ms
ActionView::MissingTemplate (Missing template home/name, application/name with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :slim, :coffee, :jbuilder]}. Searched in:
* "/home/sylanz/Documents/NimbusCC/app/views"
):
app/controllers/home_controller.rb:10:in `name'