I'm receiving the

"Called id for nil, which would mistakenly be 4 -- if you really wanted
the id of nil, use object_id"

Error Message, when my controller tries to get an object's id.

In my page users can register, login, create new game entries, rate them
and leave a review.

the create method in the ratings controller is the exact same as in the
review controller. (with different names of course)

def create
@game = Game.find_by_id(params[:game_id])
@rating = Rating.new(params[:rating])
@rating.game_id = @game.id
@rating.user_id = current_user.id
end

Giving a rating works perfectly, but assigning the game.id to
@review.game_id causes me the error...

but my relations are set, what can possibly be wrong? why is the game
object not nil when trying to create a rating, but nil when I want to
create a review?

--
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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Colin Law at Mar 24, 2013 at 12:22 pm

    On 24 March 2013 12:10, Ryo Saeba wrote:
    I'm receiving the

    "Called id for nil, which would mistakenly be 4 -- if you really wanted
    the id of nil, use object_id"

    Error Message, when my controller tries to get an object's id.

    In my page users can register, login, create new game entries, rate them
    and leave a review.

    the create method in the ratings controller is the exact same as in the
    review controller. (with different names of course)

    def create
    @game = Game.find_by_id(params[:game_id])
    @rating = Rating.new(params[:rating])
    @rating.game_id = @game.id
    @rating.user_id = current_user.id
    end

    Giving a rating works perfectly, but assigning the game.id to
    @review.game_id causes me the error...
    The error is saying that @game is nil. Look in development.log when
    the method is called to see what params[:game_id] is set to. If you
    still can't see it then put some print statements in the method to
    print the value of params[:game_id] and to show whether @game is nil.

    Also have a look at the Rails Guide on debugging which will show you
    techniques that you can use to debug your code.

    Colin
    but my relations are set, what can possibly be wrong? why is the game
    object not nil when trying to create a rating, but nil when I want to
    create a review?

    --
    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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Ryo Saeba at Mar 24, 2013 at 1:16 pm
    Maybe I need an intersection table joining Reviews and games?

    --
    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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Colin Law at Mar 24, 2013 at 1:37 pm

    On 24 March 2013 13:16, Ryo Saeba wrote:
    Maybe I need an intersection table joining Reviews and games?
    Is that in answer to my post? If so it does seem to address my
    points. I don't see what the reviews table has got to do with your
    problem as seems to be purely an issue of looking up a game id in the
    database.

    Colin
    --
    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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 24, '13 at 12:10p
activeMar 24, '13 at 1:37p
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Ryo Saeba: 2 posts Colin Law: 2 posts

People

Translate

site design / logo © 2021 Grokbase