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 8127337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:29:28+00:00 2026-06-06T07:29:28+00:00

This is just a simple question. I was trying to create a new object

  • 0

This is just a simple question. I was trying to create a new object in Rails by passing in parameters to the constructor. However, when I execute the code, I get

SQLite3::SQLException: no such column: awards.user_id: SELECT "awards".* FROM "awards"  WHERE "awards"."user_id" = 1

which means the object isn’t being constructed properly. Should I be using create instead of new? That isn’t working either.

def refresh_awards(user)

new_awards = []

if (user.karma < 40 ) #test award

    a = Award.new(:name => "Nobody Award", :description => "From Jonathan", :category => "Community", :value => 1337, :level => 0, :handle => "nobody_award")
    user.awards.append(a)
    new_awards.append(a)

end

new_awards.each do |a|

    flash[:notice] = "You received the " + a.name + "!"

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-06-06T07:29:30+00:00Added an answer on June 6, 2026 at 7:29 am

    Have you add has_many :awards to the User model? Have you added belongs_to :user to the Award model? Have you added the column user_id to the Award model (using a migration)? You’ll need to do these three things to be able to use the user.awards method you’re using. Read the Rails Guide on Associations for more detail.

    Also, append isn’t a Ruby method – the closest method would be <<. You would use it like this:

    a = Award.new(:name => "Nobody Award", :description => "From Jonathan", :category => "Community", :value => 1337, :level => 0, :handle => "nobody_award")
    user.awards << a
    

    But you could neaten this into one line of code using the create method:

    a = user.awards.create(:name => "Nobody Award", :description => "From Jonathan", :category => "Community", :value => 1337, :level => 0, :handle => "nobody_award")
    

    EDIT: To create the user_id column in the Award model, run the following code from terminal (while in your app’s directory):

    rails generate migration AddUserIdToAward user_id:integer
    rake db:migrate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[see later answer for more] I think this is just a simple rails question,
I'm just trying to create a new MySQL database with a few simple tables.
Just for the kicks i am trying to create a simple data object in
This is just a simple question. I've been reading the source of something which
This is just a simple question. Either way works. I prefer my first example,
This might be a simple question but I'm just picking this up so please
This is a super simple question that I just can't seem to find a
This should be a simple question, but I just can't recall the relevant API.
This should be a simple question, but I just can't seem to figure it
Simple question. Just wondering if this can be done without me having to enforce

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.