简体   繁体   English

如何在我的应用程序的主页上设置一个“精选部分”,该部分只能由“管理员”编辑?

[英]How do I setup a "featured section", on my home page in my app, that will only be editable by an 'admin'?

So on the home#index of my app, the first row has 4 images side by side.所以在我的应用程序的home#index上,第一行有 4 张图像并排。

That is called the featured section.这就是所谓的featured部分。 Those 4 images will be selected by the admin and they will be seen by everyone.这 4 张图片将由admin选择,每个人都可以看到。

I don't have a home model, just a homeController .我没有home模型,只有一个homeController

So, given that I want to be able to store those images as separate objects and allow regular CRUD operations on those images that will be featured ONLY on the home#index and perhaps home#edit will be the edit page...how should I approach this?因此,鉴于我希望能够将这些图像存储为单独的对象,并允许对那些仅在home#index上显示的图像进行常规 CRUD 操作,也许home#edit将是编辑页面......我应该如何接近这个?

Should I create a standalone model, called featured_images or something like that and then just pull from that model in the Home controller?我应该创建一个独立的模型,称为featured_images或类似的东西,然后在Home控制器中从该模型中提取吗?

That's one approach I thought of, but I am wondering if it is overkill to create a model just for a handful of images?这是我想到的一种方法,但我想知道为少量图像创建模型是否太过分了? But then again, those images will be changing on a regular basis - so maybe they aren't just a 'handful'.但话又说回来,这些图像会定期更改 - 所以也许它们不仅仅是“少数”。

Thoughts?想法?

"Given that you want to be able to store those images"... means it is not overkill to create a model. “鉴于您希望能够存储这些图像”......意味着创建模型并不过分。 Rails is going to make it very easy for you to store the images as models and very difficult to store them any other way. Rails 将使您很容易将图像存储为模型,而很难以其他方式存储它们。 Go with the easy way.走简单的路。

A Model object doesn't have to have an ActiveRecord (or other ORM) store backing it;模型对象不必有一个 ActiveRecord(或其他 ORM)存储来支持它; it can use the filesystem as well.它也可以使用文件系统。 Or it can store no article other than the contained logic.或者,除了包含的逻辑之外,它不能存储任何文章。 The primary purpose of the Model is to encapsulate the business logic and abstract it away from the controller layer.模型的主要目的是封装业务逻辑并将其从控制器层抽象出来。 This results in code that is easier to read, test, and maintain.这导致代码更易于阅读、测试和维护。 Where the subject doesn't involve 'business' logic, a helper or library module might be a better fit.如果主题不涉及“业务”逻辑,则助手或库模块可能更适合。

If the logic is extremely simple you can certainly get away with keeping it in the controller.如果逻辑非常简单,您当然可以将其保留在控制器中。 But before doing so, determine if you feel the simplicity is worth the tradeoff of easier readability, testability, and maintenance.但在这样做之前,请确定您是否觉得简单值得在更易读性、可测试性和可维护性之间进行权衡。 The answer might just be 'yes', but that won't usually be the case.答案可能只是“是”,但通常情况并非如此。

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

相关问题 如何让facebook页面管理员只选择他们希望我的应用管理的特定页面(manage_pages) - How do I allow a facebook page admin to select only the specific pages they want my app to manage(manage_pages) 如何使编辑用户页面在我的主页上工作? - How do I make an edit users page work on my home page? 如何在Rails应用程序的仅一页上包含JQuery库? - How do I include a JQuery library on only one page in my Rails app? 我如何在Rails测试用例中测试我的首页路由 - How do I test my home page route in rails test case 如何为访问者的Rails应用添加页面缓存? - How do I add page caching to my Rails app for visitors? 如何防止仅在我的主页上滚动? - How can I prevent scrolling on just my home page? 如何将我的主页与其他页面连接起来? - How can I connect my home page with other pages? 如何在Rails 3.2应用程序中设置开发人员特定的数据 - How do I setup developer specific data in my Rails 3.2 app 如何将Rails应用程序的主页更改为显示“注册”页面? - How to change the home page of my Rails app to show Registration page instead? 如何正确设置我的CanCanCan权限? - How do I setup my CanCanCan permissions correctly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM