Ar Chron wrote:
Ravi Dtv wrote:
def grouplist
@currentgroupid=Group.find_by_group_name(params[:group_name])
@currentgroupfriends=GroupFriend.find_all_by_user_id_and_group_id(current_user.id,@currentgroupid)
format.html {redirect_to :back}
end
What does the log tell you is nil? current_user or @currentgroupid?
a. You're assuming that @currentgroupid will always have a value, which
may be okay depending on the source of params[:group_name], which we
don't know.
b. What is populating current_user? Is that the source of the nil
error?
Thanks for your reply
def showfriendslist
@currentgroupid=Group.find_by_group_name(params[:group_name]).id
@friendsingroup=GroupFriend.find_all_by_user_id_and_group_id(current_user.id,
@currentgroupid)
respond_to do |format|
format.html {render :partial => "friendlist" }
format.xml
end
This is my controller. My current_user is the current logged in user.
I can get the groupid value into @currentgroupid.
When I tried in console
@currentgroupid=Group.find_by_group_name('testinggroup')
=> #<Group id: 23, created_at: "2010-05-17 14:00:13", updated_at:
"2010-05-17 14:00:13", user_id: 9, group_name: "testinggroup">
@currentgroupid.id
=> 23
@friendsingroup=GroupFriend.find_all_by_user_id_and_group_id('9',@currentgroupid.id )
=> [#<GroupFriend id: 15, created_at: "2010-05-19 04:36:21", updated_at:
"2010-05-19 04:36:21", group_id: 23, friend_id: 4, user_id: 9>]
@friendsingroup.id
(irb):42: warning: Object#id will be deprecated; use Object#object_id
=> -618448038
@friendsingroup.group_id
NoMethodError: undefined method `group_id' for #<Array:0xb64676b4>
from (irb):43
In view I get the following error
RuntimeError in UsersController#showfriendslist
Called id for nil, which would mistakenly be 4 -- if you really wanted
the id of nil, use object_id
Please help.. Im new to Ruby on Rails.
Thank you.
end