Topic: undefined method `all' for ActionView::Template:Class

I am trying to nest a select in a form like so:

<%= page.select("template_id", Template.all.collect { |t| [t.content, t.id] }) %>

But that is generating the following error:
undefined method `all' for ActionView::Template:Class

Here is my Template Model

class Template < ActiveRecord::Base
  has_many :pages
end

Page Model

class Page < ActiveRecord::Base
  has_many :elements
  has_many :pages_components
  has_many :components, :through => :pages_components
  has_many :users_pages
  has_many :users, :through => :users_pages
  has_many :categories
  belongs_to :template
  accepts_nested_attributes_for :categories
  accepts_nested_attributes_for :users_pages
  accepts_nested_attributes_for :template
end

Any reason why this error would appear?

Thanks in advance for any and all help!

Re: undefined method `all' for ActionView::Template:Class

Try prefixing it with two colons, e.g. ::Template.all.collect { |t| [t.content, t.id] }

Rob Anderton
TheWebFellas

Re: undefined method `all' for ActionView::Template:Class

rob-twf wrote:

Try prefixing it with two colons, e.g. ::Template.all.collect { |t| [t.content, t.id] }

This worked for me.
In my case I used it for looping through a parent/lookup record
Thanks!

Last edited by wiredin (2013-07-18 09:45:03)