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 -- 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.
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 On Mar 10, 11:50 pm, Roger Patrick <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 > > -- > Posted viahttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Sat, Mar 10, 2012 at 3:50 PM, Roger Patrick <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 > > -- > 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. > >-- 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.
Ah Cheers Bruno, that fixed my problem :) 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? -- 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.
No worries, I solved the code :) -- 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.