简体   繁体   中英

Rails REST API design

i want to create a "messenger" and i have those models:

  • Account
  • Message
  • Message channel

Account has many channels, Channel has many messages, message belongs to account(sender) Also - there is an access restrictions to control which users can read/write to channel Question is - how to create beautiful routes(and controller methods) to manage theese models..

Sorry for my bad english.(

You should use nested ressourcs! In config/routes.rb

ressources :accounts do
  ressources :message_channels do
    ressources :messages
  end
end

This will automaticly generate RESTfull URLs but you have to update all the views because of the changed _path methods. You can view the paths by calling rake routes .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM