activerecord - rails metasearch undefined method 'company_id' -
i'm new rails , need should simple problem.
when run code:
@search = user.search(params[:search]) @foundusers = @search.all.paginate :page => params[:page], :per_page => 20 @user = @search.where("users.id = ?", params[:id]) if @user.nil? @user = @foundusers.first end unless @user.company_id.nil? @company = company.find(@user.company_id) end
i following error statement: undefined method `company_id' #
i dont understand because query on database correct (select users
.* users
left outer join companies
on companies
.id
= users
.company_id
(((users
.firstname
'%s%' or users
.lastname
'%s%') or companies
.name
'%s%')) , (users.id = '11'))
and company_id user not empty.
when type puts @user.name, instead of giving me user name, gives me 'user'
many help.
@user.name prints user because .where("users.id = ?", params[:id]) still return array
try this
@users = @search.where("users.id = ?", params[:id]) @user = @users.nil? ? @foundusers.first : @users.first
Comments
Post a Comment