NoMethodError in Websocket controller

35 views
Skip to first unread message

Eugene Badin

unread,
Sep 8, 2014, 9:27:52 AM9/8/14
to rubyonra...@googlegroups.com
Here is my controller
https://gist.github.com/budkin/f02a5baed02e71a4f94f
on line 182 it throws an error



>E [2014-09-08 18:36:07.171] [[31mDispatcher[0m] NoMethodError: undefined
method `row_vectors' for nil:NilClass
>E [2014-09-08 18:36:07.171] [[31mDispatcher[0m]
/home/budkin/gamestown/app/controllers/games/gomoku_controller.rb:182:in
`block in win?'
>E [2014-09-08 18:36:07.172] [[31mDispatcher[0m]
/home/budkin/gamestown/app/controllers/games/gomoku_controller.rb:181:in
`times'
>E [2014-09-08 18:36:07.172] [[31mDispatcher[0m]
/home/budkin/gamestown/app/controllers/games/gomoku_controller.rb:181:in
`win?'
>E [2014-09-08 18:36:07.172] [[31mDispatcher[0m]
/home/budkin/gamestown/app/controllers/games/gomoku_controller.rb:97:in
`register_move'
.
.
.

this means that
`controller_store["gomoku_guess#{connection_store[:game].id}"]` invoked
on line 97 is nil, but I'm sure that I did assign it Matrix on line 60.
Why it changed? The interesting thing that this error doesn't happen on
my local machine, only when someone connects to me and we play this game
together

--
Posted via http://www.ruby-forum.com/.

Jason Fleetwood-Boldt

unread,
Sep 8, 2014, 9:44:01 AM9/8/14
to rubyonra...@googlegroups.com

Looks to me like the variable matrix is nil. Looks like it is called form line 97.

I'm not familiar enough with controller_store or connection_store (are those from WebSockets gem?) to know what to tell you. Did you put a debugger above line 97 and try to figure out why controller_store["gomoku_guess#{connection_store[:game].id}"] appears to be nil?

From am outsider's perspective, this is way too much logic in the controller. Your controller actions should always try to be no more than 7 (maybe 8) lines of code, and generally it is best to stick to REST pattern (although there are exceptions).

I would move nearly all of your domain logic code into domain objects --- either model objects or plain-old-ruby-object (PORO) objects--- then write unit tests covering the interactions between the controllers & domain objects. That way you will have more isolated parts to work with so you can figure out where the problem is.

-Jason
> --
> 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fd90b267d0c405f42284297320331215%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.
>

Eugene Badin

unread,
Sep 8, 2014, 10:05:33 AM9/8/14
to rubyonra...@googlegroups.com
>I'm not familiar enough with controller_store or connection_store (are
those from WebSockets gem?)

Yes they are. I need a websocket-rails expert, so he could answer me why
controller_store variable, once assigned, turns nil. But in the Gem's
issue tracker no one answers questions anymore, I hope I can find one
here

>Did you put a debugger above line 97 and try to figure out why
controller_store["gomoku_guess#{connection_store[:game].id}"] appears to
be nil?

I would be happy if you tell me how do I do that

>From am outsider's perspective, this is way too much logic in the
controller. Your controller actions should always try to be no more than
7 (maybe 8) lines of code, and generally it is best to stick to REST
pattern (although there are exceptions).

I'm only a beginner and I'm learning

Jason Fleetwood-Boldt

unread,
Sep 8, 2014, 10:43:23 AM9/8/14
to rubyonra...@googlegroups.com

On Sep 8, 2014, at 10:05 AM, Eugene Badin <li...@ruby-forum.com> wrote:

Did you put a debugger above line 97 and try to figure out why
controller_store["gomoku_guess#{connection_store[:game].id}"] appears to
be nil?

I would be happy if you tell me how do I do that


instructions on how to debug are here:



Please note that some Ruby developers (myself included) prefer to use byebug as an alternative to debugger. They work basically the same but instead of using the debugger gem you use the byebug gem (see https://github.com/deivid-rodriguez/byebug for instructions). Note that byebug works only if you are on Ruby 2

-Jason


Eugene Badin

unread,
Sep 8, 2014, 10:53:12 AM9/8/14
to rubyonra...@googlegroups.com
Thank you for your time!

Eugene Badin

unread,
Sep 10, 2014, 1:51:34 AM9/10/14
to rubyonra...@googlegroups.com
I found the bug. connection_store[:game] is used in :postupdaters which
is called after every action
Reply all
Reply to author
Forward
0 new messages