简体   繁体   English

Ruby on Rails 5中的全局可变变量

[英]Global mutable variable in Ruby on Rails 5

I'm building a site and want to store two variables: the target and current progress for a fundraising campaign. 我正在建立一个网站,并希望存储两个变量:筹款活动的目标和当前进度。 The organization may change the target every year, and of course will need to change the current progress. 组织可能会每年更改目标,并且当然需要更改当前的进度。 I could create a model but this seems like overkill as I would never create more than one object. 我可以创建一个模型,但这似乎有点过头了,因为我永远不会创建多个对象。 Is there an easy (and standard) way to do this? 有没有简单(标准)的方法可以做到这一点?

I'm new to rails and I've looked for answers to this question but haven't found anything exceptionally helpful - I apologize if this is a common issue. 我是Rails的新手,我一直在寻找这个问题的答案,但没有发现任何特别有用的信息-如果这是一个常见问题,我深表歉意。 Other answers depict how to store site wide variables when you do not want to edit them, but here I'd like to be able to update them as often as required. 其他答案描述了当您不想编辑站点范围内的变量时如何存储它们,但是在这里,我希望能够根据需要频繁地更新它们。

This can be an answer for you: 这可以为您提供答案:

  1. Create a model for site information probably you already have. 为您可能已经拥有的站点信息创建一个模型。
  2. Add two fields called targe and progress . 添加两个名为targeprogress字段。
  3. If you calculate progress programatically then no need to add field. 如果您以编程方式计算进度,则无需添加字段。
  4. Then make view where they can update target and progress and write logic to update that field only. 然后查看他们可以在其中更新目标和进度的地方,并编写逻辑以仅更新该字段。 Programmatically there is not a good idea other than this. 从编程上来说,除此之外没有一个好主意。 I think. 我认为。

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

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