SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Feb 19, 2009, 15:41 #1
- Join Date
- Aug 2003
- Location
- Southern California, United States
- Posts
- 1,616
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How to use model in application controler?
I want to use my User model in my application controller for a global method... how would I make it so it can use the User model? Thanks for the help guys.
Have a good day.
-
Feb 20, 2009, 02:56 #2
- Join Date
- Feb 2006
- Location
- Worcs. UK
- Posts
- 404
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Create objects based on the class. Below are three examples based on this model object
Code:class Thing < ActiveRecord::Base #an instance method def return_one 1 end #A class method (could also be defined via Thing.return_two) def self.return_two 2 end end
Code:#Use of the instance method #First grab an instance of a User object e.g find the first user @user = User.find(:first) answer_one = @user.return_one #This would also work @user = User.new answer_one = @user.return_one #Use the class method @answer_two = User.return_two
-
Feb 20, 2009, 10:26 #3
- Join Date
- Aug 2003
- Location
- Southern California, United States
- Posts
- 1,616
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It gives me errors that User is an undefined constant...
OOPS! My bad a naming error...Have a good day.
Bookmarks