Ruby on Rails - Global Variable?

前端 未结 1 756
庸人自扰
庸人自扰 2021-01-13 08:13

I am a new Ruby on Rails user and had a question. I have an idea of what I want my Users DB to look like but was wondering whether or not I should add an additional value to

1条回答
  •  北荒
    北荒 (楼主)
    2021-01-13 08:58

    A global variable doesn't fit your need. It doesn't spread across all the Ruby processes. If your web server spawns 5 ruby processes to handle 5 request at the same time, the variable defined in the first process won't be visible to the others.

    There are other solutions available. You can use a database and store the flag/information on the database. Otherwise, you can use a file and store the value in the file. The best solution would be an in-memory shared data source, such as memcached or Redis.

    0 讨论(0)
提交回复
热议问题