Forum: Ruby on Rails accessing controller variable from view

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9f4a65c520a69cd357d830661e172272?d=identicon&s=25 JannaB (Guest)
on 2009-06-09 17:04
(Received via mailing list)
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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-06-09 17:46
(Received via mailing list)
On Jun 9, 4:04 pm, JannaB <mistressja...@hotmail.com> 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
This topic is locked and can not be replied to.