Ho un modello Artwork
che è manipolato solo dagli endpoint API al momento. (Vedrai perché questo è importante a breve). Tali endpoint API sono dichiarate in questo modo nel mio file routes.rb
:Rails 3: respond_with errori sull'helper URL non definito
namespace :api do
namespace :v1, :defaults => { :format => :json } do
resources :artworks, :only => [:create, :destroy, :index, :show, :update]
Ciò si traduce nei seguenti percorsi:
api_v1_artworks GET /api/v1/artworks(.:format) api/v1/artworks#index {:format=>:json}
POST /api/v1/artworks(.:format) api/v1/artworks#create {:format=>:json}
api_v1_artwork GET /api/v1/artworks/:id(.:format) api/v1/artworks#show {:format=>:json}
PUT /api/v1/artworks/:id(.:format) api/v1/artworks#update {:format=>:json}
DELETE /api/v1/artworks/:id(.:format) api/v1/artworks#destroy {:format=>:json}
codice rilevante:
class Api::V1::ArtworksController < Api::V1::ApiController
def create
artwork = Artwork.create(artwork_params)
respond_with artwork
end
Il problema
Quando #create
riesce, respond_with
soffoca:
`undefined method `artwork_url' for #<Api::V1::ArtworksController:0x007fea1b4c67f8>`
Si aspetta il supporto per il HTTP posizione di essere artwork_url
. Come posso dire di usare invece api_v1_artwork_url
? Posso alias l'helper dell'URL?
solo verificare questo problema e io sono un po 'confuso sul perché dobbiamo aggiungere lo spazio dei nomi .. non riesco a trovare su documentazione ufficiale (o forse ho trascurato di esso) – giosakti
Vorrete leggi i percorsi polimorfi: http://ryanbigg.com/2012/03/polymorphic-routes/, http://api.rubyonrails.org/classes/ActionDispatch/Routing/PolymorphicRoutes.html – rossta
Non funziona. si ottiene "metodo non definito' api_RESOURCE_url 'per # " – ajbraus