i have a profile controller.but i want to use User model to save some fields in users table.So how can i load User model in profile controller
A:
You can load any model in any controller - just call it as you would normally.
If you need to load a User
from your Profiles
controller, you can just use User.find_by_whatever()
, User.new
, current_profile.user
- not sure how your associations are set up, but there shouldn't be any access restrictions.
Jeriko
2010-06-09 10:38:23
when i use like@user = User.new;@a = User.find(:all)it shows error "uninitialized constant ProfileController::User"any thing am i missing?
ashok
2010-06-09 11:07:46
You definitely have a User model set up? Can you call it fine from the Users controller, or isn't there one?
Jeriko
2010-06-09 11:30:18
+1
A:
model are independent entity and you can call it from any controller.
There can be a model without a controller and vice-versa.
For you question take a example below
class ProfileController < ApplicationController
def some_method
@user = User.find(params[:user_id])
if @user.update_attributes(params[:user])
// some action
else
// some action
end
end
end
Salil
2010-06-09 10:47:40