# Accessing controller variable from view

**URL:** <https://www.ruby-forum.com/t/accessing-controller-variable-from-view/169851>\
**Category:** Rails\
**Created:** [June 9, 2009, 5:04pm UTC](https://www.ruby-forum.com/t/accessing-controller-variable-from-view/169851 "2009-06-09T17:04:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JannaB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@JannaB](https://www.ruby-forum.com/u/JannaB)\
**Post date:** [June 9, 2009, 5:04pm UTC](https://www.ruby-forum.com/t/accessing-controller-variable-from-view/169851/1 "2009-06-09T17:04:50Z")

</div>

In my ApplicatoinController I have:

class ApplicationController \< ActionController::Base

MOBILE\_USER\_AGENTS = ‘palm|palmos|palmsource|iphone|blackberry|  
nokia|phone|midp|mobi|pda|’ +  
‘wap|java|nokia|hand|symbian|chtml|wml|  
ericsson|lg|audiovox|motorola|’ +  
‘samsung|sanyo|sharp|telit|tsm|mobile|mini|  
windows ce|smartphone|’ +  
‘240x320|320x320|mobileexplorer|j2me|sgh|  
portable|sprint|vodafone|’ +  
‘docomo|kddi|softbank|pdxgw|j-phone|astel|  
minimo|plucker|netfront|’ +  
‘xiino|mot-v|mot-e|portalmmm|sagem|sie-s|  
sie-m|android|ipod’

def is\_mobile\_device?  
request.user\_agent.to\_s.downcase =~ Regexp.new  
(MOBILE\_USER\_AGENTS)  
end

My problem is in my /views/layouts/application.html.erb I have:

\<% if is\_mobile\_device? %\>

I get:

undefined method `is\_mobile\_device?’ for #ActionView::Base:0x6752ff0

How can I refer to is\_mobile\_device? from this view – as well as all  
views and controllers – I want to be DRY about this - how can I do  
that? -Janna B.

---

<div class="post-metadata">

**Author:** ![JannaB](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/df788c/32.png) [@JannaB](https://www.ruby-forum.com/u/JannaB)\
**Post date:** [June 9, 2009, 5:46pm UTC](https://www.ruby-forum.com/t/accessing-controller-variable-from-view/169851/2 "2009-06-09T17:46:13Z")

</div>

On Jun 9, 4:04 pm, JannaB [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How can I refer to is\_mobile\_device? from this view – as well as all  
> views and controllers – I want to be DRY about this - how can I do  
> that? -Janna B.

Lookup helper\_method

Fred
