I tried different ways to retrieve json-data unsuccessfully
my order.js.coffee
$.ajax(
url: "/orders/", // want "/orders/1"
dataType: "JSON"
).done (data) ->
console.log data.status
my controller:
class OrdersController < ApplicationController
respond_to :json, :js, :html
def show
@order = Order.find(params[:id])
respond_with @order
end
....
my show.json.jbuilder
json.extract! @order, :id, :status
and here my route:
get '/orders/:id', to: 'orders#show', defaults: {format: :json}
resources :orders, only: [:new, :create]
...
I got a lot of errors with different approach.
Started GET "/orders/" for 127.0.0.1 at 2014-10-07 01:07:36 +0200
ActionController::RoutingError (No route matches [GET] "/orders"):
or
ERROR bad URI `/orders/%3C%=%20order.id%20%%3E'
idfrom in your CoffeeScript? Is yourorder.js.coffeesupposed to beorder.js.coffee.erbperhaps?erbin you coffeescript that is loaded outside the context of the controller and 2) expect that making agetrequest to the index action would do anything when you expressly limit the orders action tonewandcreateactions in the controller?url: "/orders/1where 1 is a parameter that I want to pass from the show action$.get('/orders/1')url: "/orders/1but1is a parameter that change at every new order. In other word I need something like this:/orders/:id, thanks for your time.