简体   繁体   English

在控制器中创建一个全新的动作会更好还是在Ruby on Rails中创建一个新的控制器?

[英]Would it be better to create an entirely new action in my controller or should I create a new controller in Ruby on Rails?

Basically I have an existing CollegeClass Controller that has the default basic RESTful actions like show for showing the webpage for that college class,edit for editing, and update for the post action of editing the page itself. 基本上,我有一个现有的CollegeClass Controller,该控制器具有默认的基本RESTful操作,例如show用于显示该大学课程的网页,edit用于编辑,以及针对编辑页面本身的后期操作进行更新。 I need to add an additional single "About the class" webpage to this resource which will not add another model. 我需要一个额外的单一的 “关于类”网页添加到这个资源,这将不添加其他模型。 It will just add another field to the existing CollegeClass table for the html that will present the new page. 它将向现有的CollegeClass表中添加另一个字段,以显示新页面的html。

Should I create a controlller exclusive to the "About the class"? 我应该创建“关于课程”专用的控件吗? Or should I add on into the CollegeClass controller new actions? 还是应该在CollegeClass控制器中添加新操作? Or do I need to nest this? 还是我需要嵌套它?

Thanks for your help 谢谢你的帮助

I would go with the custom action and just route it inside college routes as 我会采用自定义操作,然后将其作为大学路线

resources :colleges do
  member do
    get 'about'
  end
end


CollegeController < ApplicationController
  def about
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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