Re: Re: User and Game Association help.

Colin Law
2012-02-01T11:59:51Z

On 1 February 2012 11:39, Christopher Jones
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:
>> If you have a user, current_user for example, then his games will be
>> current_user.games.
>
> At the moment I have under the profile @user.games that should return
> all games associated with that particular user but no results.

In that case the user has no games.

>
> I would like it so that when a new game is added it will associate
> itself with the current logged in user rather than entering the
> username. Would I have to do this as part of the _form.html.erb input
> for games or must this be declared in a model?

Assuming the current user is available as current_user then
current_user.games will return all his games.

As I said if you work through some tutorials and the guides you will
save yourself a lot of time in the long run.  Also after doing this
you will look back here at the questions you asked and be embarrassed
:)

Also read up about using the rails console and have a look at the
rails guide on debugging.

Colin

>
> All help will be greatly appreciated.
>
> --
> 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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
>



--
gplus.to/clanlaw