开发者

How should I store variables between method calls in rails?

开发者 https://www.devze.com 2023-02-07 06:48 出处:网络
I\'m fairly new to RoR I have a controller and within that controller I need to store an instance variable I create in the new method and reference it again in the create method.

I'm fairly new to RoR I have a controller and within that controller I need to store an instance variable I create in the new method and reference it again in the create method.

Now because HTTP is stateless the only reasonable way I have found to do this is store the id of the model that the instance variable contains in session[] and then recall this value from session[] again in the create method. I'm just concerned about security using this way of storing the variable's id, I need to make sure that a user can't change the value of what I've stored in sessi开发者_StackOverflowon[]

Is there a better way for me to do this? Is it safe? Or should I try something else?


If you can't recalculate that model id on every request, using a session is ok.
Here's more info on session security in Rails.


if you can load the model in the new method, load it from create using the same way you load it in new

0

精彩评论

暂无评论...
验证码 换一张
取 消