0
我想寫一個簡單的API使用紅寶石和鐵軌,幾乎得到它的工作,我只有一個問題。當我嘗試創建嵌套資源時,收到「未定義的方法」錯誤。嵌套的資源缺少_url
我有兩個模型,一個是用戶模型,一個是記錄模型。他們在routes.rb中設置爲這樣:
resources :users, :except => [:new,:edit] do
resources :records, :except => [:new,:edit]
end
我的記錄控制器包含以下內容:
def show
respond_with @user.records.find(params[:id])
end
def create
respond_with @user.records.create(params[:record])
end
當我打電話放映參數,它的工作原理和返回模型。當我張貼創建我得到以下錯誤:
NoMethodError: undefined method `record_url' for #<RecordsController:0x007fea3682a5c8>
我不知道爲什麼,這是發生,但如果任何人有任何想法,我將不勝感激。另外,如果需要更多代碼來幫助,請告訴我,以便我可以添加它。
忘了加我耙路線:
user_records GET /users/:user_id/records(.:format) records#index
POST /users/:user_id/records(.:format) records#create
user_record GET /users/:user_id/records/:id(.:format) records#show
PUT /users/:user_id/records/:id(.:format) records#update
DELETE /users/:user_id/records/:id(.:format) records#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
輝煌,謝謝。我花了大約兩個小時在網上搜索。 – 2012-08-01 03:13:48