Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:53:36+00:00 2026-05-30T22:53:36+00:00

I have a problem at the moment and am not sure what I should

  • 0

I have a problem at the moment and am not sure what I should do. It is
in regards to relationships between tables and whether I need foreign
keys.

I have two tables in my database; users and games. Users includes all
the users information (username, email, address, password etc.) Games
includes all the games information (name, genre, console user_id). As
you may have noticed the games table includes the users id in order to
associate the relationship between the two which is every game needs an
associated user.

What I wish to do is on each games show.html.erb page, I have a button
which should send an email to the owner of that game in order to let
them now that the currently signed in user is interested in trading that
game.

I am wondering how I would do this. Does the user_id automatically link
all the users associated data or just the id. If not then how would I
declare the users email as a foreign key in order for me to call the
users email to be sent to?

Any help would be much appreciated. Thank you

Christopher Jones

UPDATE

Hey I had the following in my games_controller show section and it did not work. It threw the following error: undefined method `email’ for “chris230391@googlemail.com”:String.

def show
@game = Game.find(params[:id])

respond_to do |format|
  GameTrade.game_interest(@game.user.email).deliver
  format.html { redirect_to root_url }
  format.json { render json: @game }
end
end

So I changed it to the following in order to break down the problem and find out what line it broke on and it stated that the block was on line 19 which is the line g = GameTrade.game_interest(email). I got the following error:

undefined method `email’ for “chris230391@googlemail.com”:String

Any ideas? the code is below

def show
  @game = Game.find(params[:id])

respond_to do |format|
  user = @game.user
  email = user.email
  g = GameTrade.game_interest(email)
  g.deliver
  format.html { redirect_to root_url }
  format.json { render json: @game }
end
end

The following code is that of my Game_trade.rb in the mailer section:

  class GameTrade < ActionMailer::Base
    default :from => "christopher@aol.com"

    def game_interest(user)
      @user = user
      mail :to => user.email, :subject => "Game Interest"
    end
   end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:53:37+00:00Added an answer on May 30, 2026 at 10:53 pm

    Take a look at this Stack Overflow question regarding Rails and referential integrity. You may want to look into the foreigner gem for adding and removing foreign keys during Rails migrations.

    However, I’m curious as to why you’re creating foreign key constraints beyond the game->user constraint you already have. Is there a reason you’re denormalizing the username and email fields?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bizarre problem at the moment, I am just making a start
I have a problem and I am stack. If anyone have a spare moment
I'm building a micro site at the moment and I have a problem. I
I am playing around with cuda. At the moment I have a problem. I
The following code summarizes the problem I have at the moment. My current execution
I'm having a blonde moment, here is my problem: Break down: I have an
Not sure if the derived page is actually relevant to the problem here, but
I am not sure what is the exact term for this problem. Basically, I
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.