# Declare global variable in views

**URL:** <https://www.ruby-forum.com/t/declare-global-variable-in-views/167210>\
**Category:** Rails\
**Created:** [May 5, 2009, 3:50pm UTC](https://www.ruby-forum.com/t/declare-global-variable-in-views/167210 "2009-05-05T15:50:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nike](https://www.ruby-forum.com/u/nike)\
**Post date:** [May 5, 2009, 3:50pm UTC](https://www.ruby-forum.com/t/declare-global-variable-in-views/167210/1 "2009-05-05T15:50:20Z")

</div>

how to declare a variable globally in views without writing in  
controller,model or in config

---

<div class="post-metadata">

**Author:** ![nike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nike](https://www.ruby-forum.com/u/nike)\
**Post date:** [May 5, 2009, 6:20pm UTC](https://www.ruby-forum.com/t/declare-global-variable-in-views/167210/2 "2009-05-05T18:20:12Z")

</div>

On May 5, 2:50 pm, Nike M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## how to declare a variable globally in views without writing in controller,model or in config

that doesn’t sound like a good idea. If you can elaborate on what  
you’re trying to do someone might be able to chip in with a neater way  
of doing things.

Fred

---

<div class="post-metadata">

**Author:** ![nike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/dbc845/32.png) [@nike](https://www.ruby-forum.com/u/nike)\
**Post date:** [May 5, 2009, 6:24pm UTC](https://www.ruby-forum.com/t/declare-global-variable-in-views/167210/3 "2009-05-05T18:24:21Z")

</div>

I agree with Frederick.

Depending on what you need, using a session key/value or cookie may be  
the appropriate way to maintain the data.

On May 5, 9:19 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
