0
我正在研究一個Rails項目,它將通過URI公開一組資源。我的問題如下:設計三元關係的寧靜URI
考慮這些模型,學生,筆記和課程。每課可以有許多由學生髮布的筆記。在活動記錄的文獻:
class Lesson < ActiveRecord::Base
has_many :notes
end
class Student < ActiveRecord::Base
has_many :notes
end
class Note < ActiveRecord::Base
belongs_to :lesson
belongs_to :user
end
現在我想知道的URI設計和資源設計,支持以下情形:
檢索該帖由學生ID爲5 課所有筆記列表ID爲4
請注意,如果我在routes.rb中定義的資源是這樣的:
resources :lessons do
resources :notes
end
resources :students do
resources :notes
end
然後我可以通過「/ lessons/4/notes /」和「/ students/5/notes」來訪問筆記,但是我之前解釋過的查詢怎麼樣?
在此先感謝!
感謝您的回覆。我將使用這個URI來** POST **數據。所以我認爲我應該使用http頭來** POST **數據,或者我應該使用相同的格式,即「/ notes?lesson = 4&student = 5」來發布。 –
不要發佈到這樣的URI。查詢參數'lesson'和'student'應作爲搜索的參數來讀取:給我一個減肥和學生的所有筆記。如果您想要添加或更改筆記,課程或學生,請使用'POST'或'PUT'來針對正確的URI執行此操作。 – 2012-11-06 21:20:00