回答
def received
@messages = Message.to(current_user)
end
def sent
@messages = Message.from(current_user)
end
在你message.rb定義這兩個命名範圍的方法。
或者託尼Fontenot指出:
def received
@messages = current_user.messages.to
end
def sent
@messages = current_user.messages.from
end
保持簡單
/messages?view=sent
在你index
方法
def index
@messages = case params[:view]
when 'sent'
Messages.sent
when 'received'
Messages.received
else
Messages.all
end
end
見inherited_resources
插件如何處理作用域。
map.resources :messages, :collection => { :sent => :get, :received => :get }
然後在你的messages_controller.rb:
由誰來發?收到誰?不完整的答案伊莫。提問者還要求它遵守RESTful慣例。這不是。該模型也可能被稱爲「消息」。 – 2009-12-01 08:06:37
然後,NachoF將需要調整路線以指示請求的主題。 '/ client/73/messages?view = sent' 並用適當的查找器替換Messages。[all | sent | received]。 可能: 'client.messages.sent' 但在問題NachoF沒有提供有關消息關聯的信息。 – 2009-12-01 17:05:19
然後他會使用參數來調用發送消息關聯?如果我以「delete_all」的形式發送這些參數呢? – 2009-12-01 22:19:12
- 1. 幫助與鐵軌declarative_authorization
- 2. 幫助與鐵軌json和jquery
- 3. 紅寶石在鐵軌上的幫助
- 4. 需要幫助在鐵軌上播種
- 5. WCF休息幫助頁
- 6. CakePHP標準標籤與HTML幫助
- 7. 幫助寶石在軌道上休息3
- 8. 紅寶石在鐵軌上的協助幫助
- 9. Paypal與鐵軌
- 10. 幫助與軌道路線
- 11. 幫助與軌道協會
- 12. 沒有幫助WCF休息模板40
- 13. 鐵軌分頁與標籤雲
- 14. authlogic軌幫助
- 15. 幫助軌belongs_to的
- 16. 谷歌文檔與鐵軌
- 17. .NET標準項目構建失敗,沒有幫助的消息
- 18. 幫助需要與軌道facebook連接
- 19. 測試使用cookies的鐵軌助手
- 20. 條形標準連接帳戶與鐵軌 - 如何申請折扣?
- 21. 休眠標準
- 22. 休眠標準
- 23. 休眠標準
- 24. 休眠標準
- 25. 休眠標準
- 26. 標準休眠
- 27. 休息排名與多個標準的關係
- 28. 多個單元格標準Vlookup與外出幫助列
- 29. 幫助與NHibernate標準查詢GROUPBY財產
- 30. 休眠例外幫助:TransientObjectException
做@messages = current_user.messages.to'和'@messages = current_user.messages.from'不是更好嗎? – 2009-12-01 16:00:33
是的,你是對的。 – 2009-12-01 22:17:35