在Rails中,如何通过单击一个按钮来更改三个单独页面上的边框颜色?

时间:2022-01-26 20:31:52

In my rails application I have a page where there are several "proposals". I need a way where I can go in and select the "winning proposal". Then I want that proposal's div border color to change to green. The proposal also exists on three other pages so I would like to change its color in those places as well as the text in those divs. What's the best way to do this in rails?

在我的rails应用程序中,我有一个页面,其中有几个“提案”。我需要一种可以进入并选择“获胜提案”的方式。然后我希望该提案的div边框颜色变为绿色。该提案还存在于其他三个页面上,因此我想更改这些地方的颜色以及这些div中的文本。在rails中执行此操作的最佳方法是什么?

1 个解决方案

#1


1  

I would have a field in a Proposal model that is a boolean, and indicates if it is winning or not. Have it default to false. Thats :default => false in the migration.

我会在Proposal模型中有一个布尔值的字段,并指示它是否获胜。它默认为false。多数民众赞成:迁移中默认=> false。

Then in your view, if the proposal is winning, you could give your div a class like .winning-proposal which would correspond to a CSS class you would put in proposal.css.scss or whatever is in your stylesheets directory. You would not include this class in the div if the Proposal not winning.

然后在您看来,如果提案获胜,您可以为您的div提供类似.winning-proposal的类,该类对应于您将放在proposal.css.scss中的CSS类或者样式表目录中的任何类。如果提案没有获胜,您不会在div中包含此类。

To set the winning proposal, you simply need to update attributes of the Proposal instance and set the winning boolean column for the model to true.

要设置获胜提议,您只需更新Proposal实例的属性,并将模型的获胜布尔列设置为true。

Hope that makes sense!

希望有道理!

#1


1  

I would have a field in a Proposal model that is a boolean, and indicates if it is winning or not. Have it default to false. Thats :default => false in the migration.

我会在Proposal模型中有一个布尔值的字段,并指示它是否获胜。它默认为false。多数民众赞成:迁移中默认=> false。

Then in your view, if the proposal is winning, you could give your div a class like .winning-proposal which would correspond to a CSS class you would put in proposal.css.scss or whatever is in your stylesheets directory. You would not include this class in the div if the Proposal not winning.

然后在您看来,如果提案获胜,您可以为您的div提供类似.winning-proposal的类,该类对应于您将放在proposal.css.scss中的CSS类或者样式表目录中的任何类。如果提案没有获胜,您不会在div中包含此类。

To set the winning proposal, you simply need to update attributes of the Proposal instance and set the winning boolean column for the model to true.

要设置获胜提议,您只需更新Proposal实例的属性,并将模型的获胜布尔列设置为true。

Hope that makes sense!

希望有道理!