如何在 Rails 中为模型创建别名
我有一个应用程序,用户在其中创建“板”,
我必须更改网站的名称,现在用户创建“墙”。
目前我有以下网址:
http://mysite.com/boards
http://mysite.com/boards/i/edit
有没有办法将名称“boards”别名为“walls”,这样我的网址将如下所示:
http://mysite.com/walls
http://mysite.com/walls/1/edit
等,而无需更改表、模型和代码的名称?
routes.rb
resources :boards
如果可能的话,我还想为路径添加别名:
即使资源编写如下,new_board_path 仍然有效:
resources :walls, :controller => :板
谢谢
I have an application where users created 'boards'
I have had to change the name of the website and now users create 'walls'.
Currently I have the following url's:
http://mysite.com/boards
http://mysite.com/boards/i/edit
Is there a way to alias the name 'boards' to 'walls' so my URL's will be as follows:
http://mysite.com/walls
http://mysite.com/walls/1/edit
etc without having to change the name of the table, models, and code?
routes.rb
resources :boards
I would also like to alias the paths if possible:
new_board_path would still be valid even if resources are written as follows:
resources :walls, :controller => :boards
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: