Ruby on Rails.如何只显示一次记录? [英] Ruby on Rails. How to show record only once?
问题描述
我想知道如何仅在创建后才显示记录.所以我只想展示一次.
I want to know how to show a record only exactly after it was created. So i want to show it only once.
看看吧.我有一个名为 Claim 的模型.用户创建新声明(用户是匿名的).我只想在用户创建它后才显示此声明,而不再显示.我该怎么做?
Just see. I have model called Claim. User creates new Claim (user is anonymous). I want to show this Claim only ofter user creates it and never again. How can I do it?
我认为我可以使用 flash hash,但我认为从用户数据创建符号还不够安全.
I think that I can use flash hash, but i think it is not enough secure to create symbols from user data.
推荐答案
您可以在模型上设置一个 viewed
属性,并在 show 操作中将其设置为 true.如果 viewed
为真,则跳过渲染视图.
You could have a viewed
attribute on your model that you set to true in the show action. If viewed
is true then skip rendering the view.
unless thingy.viewed
thingy.viewed = true
thingy.save
render like normal...
end
这篇关于Ruby on Rails.如何只显示一次记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!