undefined local variable or method 'game'

I am doing a web shop assignment and have got a problem with my action
mailer.

I get an error undefined local variable or method 'game'

I have the following in my mailer:

  def game_interest(user, game)
    @user = user
    @game = Game
    mail :to => user.email, :subject => "Game Interest"
  end

and the following in my controller:

  def email

      @game = Game.find(params[:id])
        respond_to do |format|
        user = @game.user
         email = user.email
          g = GameTrade.game_interest(user, game)
           g.deliver
      format.html { redirect_to root_url }
      format.json { render json: @game }
    end
  end

Basically its an argument error.

  def game_interest(user, game)
    @user = user
    @game = Game
    mail :to => user.email, :subject => "Game Interest"
  end

It should be

  def game_interest(user, game)
    @user = user
    @game = game
    mail :to => user.email, :subject => "Game Interest"
  end

As you are passing the game object to game_interest function,but while
passing it you are using Game class.

-Hari

You are not passing the variable game to method ‘email’.
g = GameTrade.game_interest(user, game)

Don’t you have to do this?
g = GameTrade.game_interest(user, @game)

Bruno Coelho Santiago

Ah Cheers Bruno,

that fixed my problem :slight_smile:

I am wondering if there is any way to do current_user as well as user in
one post e.g.

hi user (jon)

the current_user (adam) has registered an interest in your post?

No worries, I solved the code :slight_smile: