SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot ricklach's Avatar
    Join Date
    Nov 2004
    Location
    Victoria BC
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A question on Global Scope

    I am trying to call a method (Voter.find_all) in a different controller other than voters_controller. When I use it in a different controller, it seems to return a blank record set. Is this a global scope problem and if so how do I declare the method as global.

    Rick
    Ruby, Ruby when will you be mine

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume that Voter is an activerecord model? Then it should return the same list for both controllers. Do you have so code to show? Maybe there's something wrong with it.

  3. #3
    SitePoint Zealot ricklach's Avatar
    Join Date
    Nov 2004
    Location
    Victoria BC
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, this is where things get a little fuzzy for me. In model eda_officer.rb I only have
    Code:
     class EdaOfficer < ActiveRecord::Base
    has_many :voters
    end
    but in the controller I have
    Code:
    def auto_complete_for_voter_lastname
        value = params[:voter][:lastname]
        @voters = Voter.find(:all,
          :conditions => ['LOWER(lastname) LIKE ?', "#{value.downcase}%" ],
          :order => 'name ASC',
          :limit => 10)
         # @voters = Voter.find(1)
        render :partial => 'officers'
      end
    and of course I also have a voter.rb model and controller and in the voter.rb file I have
    Code:
    class Voter < ActiveRecord::Base
    belongs_to :eda_officer
    end
    . Does this help?

    Rick
    Ruby, Ruby when will you be mine


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •