I’m having an error I don’t understand for several days. I have a class
Game, which have 2 attributes :
class Game < ActiveRecord::Base
has_many :players
has_many :cards, as: :cardable
Then I create a new instance and access the players it fails with void
value expression.
do you know how to tail the development log (I assume not because you
are using puts statements instead of logger.debug statements). You
probably want to get used to using logger.debug(x.inspect) (where x is
the variable you want to look at) for debugging.
Please tail the development log and show us the controller action &
parameters (copy and paste the whole thing for us).
Also, when asking for help, show us the entire Controller code,
beginning with the class definition. (you did not specify if the code is
inside of an action)
To debug your problem, you need to know what the value of game_params
is, which you did not show us.
Thank you Jason for your fast reply. I didn’t know about the default
logger, I have changed my code. Yes it is in a controller, in the create
action: gist:d138a4f2c76bb4b32dd2 · GitHub
The full log:
Started POST “/game” for 127.0.0.1 at 2014-09-03 00:14:49 +0200
Processing by GameController#create as HTML
Parameters: {“utf8”=>“V”,
“authenticity_token”=>“gx7TovN+tZbMxOTc91l5P/5jqviBx
eO9vlJQaxJ19No=”, “game”=>{“small_blind”=>“1”, “big_blind”=>“2”,
“player_number”
=>“2”}, “commit”=>“New game !”}
cards
#<ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_Collect
ionProxy_Card:0x3b762e8>
0
players
Completed 500 Internal Server Error in 114ms
SyntaxError
(C:/site/app/models/player.rb:48: voi
d value expression):
app/controllers/game_controller.rb:11:in `create’
Thank you for your remarks but it doesn’t seem to be the reason here:
“cards” is not in “Parameters” but it successfully accesses the
attribute when I log it.
I have run another page to display a game (already existing in the db),
I have got the same error “void value expression” when trying to access
the attribute “players” of the Object “game” (previously it worked
fine).
It appears that rails doesn’t know about the “players” attribute. Where
should I check the definition ?
A little up for this problem which seems complex since nobody has the
answer yet.
You have not quoted the previous message so I had to search back
through the thread to find what you were talking about. Remember this
is a mailing list not a forum (though you may be accessing via a forum
like interface.
Post the start of games.rb (not the methods, just the declarations at
the front).
A little up for this problem which seems complex since nobody has the
answer yet.
You have not quoted the previous message so I had to search back
through the thread to find what you were talking about. Remember this
is a mailing list not a forum (though you may be accessing via a forum
like interface.
Post the start of games.rb (not the methods, just the declarations at
the front).
Colin
Hello Colin,
Yes I’m using the forum interface, didn’t know about the mailing list
behind.
Here is my game class definition
class Game < ActiveRecord::Base
has_many :players
has_one :board
has_many :cards, as: :cardable
On Tuesday, 2 September 2014 18:20:57 UTC-4, Ruby-Forum.com User wrote:
eO9vlJQaxJ19No=", “game”=>{“small_blind”=>“1”, “big_blind”=>“2”,
SyntaxError
(C:/site/app/models/player.rb:48: voi
d value expression):
app/controllers/game_controller.rb:11:in `create’
This is not a runtime error, this is a syntax error in app/models/player.rb. It’s happening at runtime because that line
autoloads the Player class.
You’ll want to check the code before and after line 48 for things that
aren’t correctly structured, or post it here.
I really like my IDE which shows me syntax errors hi-lighted in red. Any
good IDE (Sublime, Rubymine, etc) should do this for you and it’s a good
thing to adopt such a tool.
What happens if you say
puts @game.players.inspect
Colin
The same result as previously since the @game.players is nil, it fails
with “void value expression”.
You would not get the error if it were nil. nil.inspect is a
perfectly valid statement.
Post the full stack trace of the error along with the relevant bit of
source (the version with puts @game.players.inspect) and give us a
line number.
What versions of ruby and rails are you running?
Also try going back through the versions of code till you find one
that did not show the problem and see what changes you made.
Something must have changed to make it behave differently. Either in
the code or the running environment (version of ruby and so on).
Thank you very much everybody, this was as simple as you told: parse
error in player.rb.
I wasn’t looking in the good direction at all and was confused by the
fact it was thrown while accessing the attribute (and then initializing
the class).
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.