其他 RESTful 方法和操作 DRY
我有一个模型,其中有几列我想呈现给界面以更新为不同的页面。我的问题涉及组织路线和控制器操作的最佳 Rails 方式是什么。
例如,用户具有“个人资料”和“帐单地址”。两个页面都仅包含来自用户模型的列,它们是必需的、一对一的,而且很小,因此额外的模型似乎是不必要的开销。
似乎我必须为我想要呈现的每个不同视图添加 GET 和 PUT,是吗?因此,我不仅需要编辑/更新,还需要 edit_profile/update_profile 和 edit_billing/update_billing 等。
I have a model that has several columns I want to present to the interface to update as different pages. My question deals with what is the best rails-y way to organize your routes and controller actions.
For example, a User has a "Profile" and a "Billing Address". Both pages contain columns only from the User model, they are required and one-to-one, and small, so an additional model seems like unnecessary overhead.
It seems like I have to add a GET and a PUT for each different view I want to present, is that right? So instead of just edit/update, I'd need edit_profile/update_profile and edit_billing/update_billing, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
即使没有配置文件模型,我认为您仍然可以使用 ProfileController 和配置文件视图,例如“views/update.html.erb”,并将其路由为“/users/123/profile/”。
在我看来,我们不需要将每个视图或控制器严格映射到一个模型。 Rails是基于ROA的,但这里的“资源”可以更抽象。
Even without a Profile model, I think you still can use ProfileController and views for profile like 'views/update.html.erb', and make it route as '/users/123/profile/'.
In my opinion, we don't need to mapping every view or controller to one model strictly. Rails is based on ROA, but here the "resource" can be more abstract.