在 Ruby-on-Rails 中处理评级 api/函数的适当方法是什么?
考虑到 Ruby-on-Rails MVC 框架,处理评级 api/函数的最佳方法是什么。
如果我想让用户能够对“故事”进行评分,而无需实际编辑它们,那么最好的方法是什么。我不想将故事置于编辑模式,我只想获取故事的 ID 并在评级表中添加一条记录。
仅创建一个视图(其中评级表打开进行编辑,但链接的故事仅处于显示模式)是否正确?
显然,当涉及到 MVC 和 RonR 时,我是一个初学者,但我只想在脑海中找到正确的方法:)
Given the Ruby-on-Rails MVC framework, what is the best way to handle a rating api/function.
If I want to give users the ability to rate "stories", without actually editing them, what would be the best route to take. I don't want to put the story into edit mode, I just want to grab the story's ID and add a record in a Ratings table.
Would it be correct just to create a VIEW, in which the Ratings table is open for edit, but the linked stories are just in display mode???
Obviously I'm a beginner, when it comes to MVC and RonR, but I just want to get the proper way of doing this straight in my head :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将有一个评级模型,它将存储所有评级和所有故事之间的关联。
从那里您将有一个评级控制器,主要用于创建评级(如用户对故事进行评级)。
当用户创建评级时,请求应发送至RatingsController#create。
在故事视图页面上,您可以通过 GET 参数传入故事 id 的参数来链接到 RatingsController#create(使用 嵌套资源)。
You would have a ratings model which would store the association between all the ratings and all the stories.
From there you would have a ratings controller that would be there to mainly create a rating(as in a user rates a story).
When a user creates a rating, the request should go to the RatingsController#create.
On the story view page, you would link to the RatingsController#create by passing in the paramater of the story id through the GET paramaters(by using nested resources).