On 20 May 2010 16:35, Ravi Dtv <[email protected]> wrote:
> 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

That is because @friendsingroup is an array because you have used
find_all_by_...  The clue is in the error message.  It says that class
Array has not got a method group_id

>
> 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

That means that you have used something.id where id is nil.  You still
have not told us which line in the view is giving the error.  Look at
the error message and see which line it is, then look to see what id
you are using on that line and most likely you will find the nil
object.  Then you just have to work out why it is nil.  In order to
avoid your view crashing you could test it for nil and put a message
in the view instead of allowing it to crash.

I also suggest also that you have a look at the Rails Guide on
debugging.  It will show you ways of breaking in to your code to
inspect the variables.  I use ruby-debug when I have this sort of
problem.

Colin

>
>
> Please help.. Im new to Ruby on Rails.
>
> Thank you.
>
>
>  end
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to