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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:47:06+00:00 2026-05-21T11:47:06+00:00

I’m a little slow when it comes to programming, but I enjoy it and

  • 0

I’m a little slow when it comes to programming, but I enjoy it and try to learn as much as I can. So apologies in advance if i’m not clear enough with my question.

I have an app with a sole purpose for DJs to review songs and the song reviews to be grouped by state. 5 Fields… songid, state, stdjlike, stthinkclublike, stplait (Horrible names I know, but they help me to remember what they are :)).

Once a user decides to review a song, they will be asked 3 questions which are answered on a scale of 1 to 5, the form collects the 3 answers as well as the users state and the id of the song. Most of the time the database will just find the state and song id, then add the new data to the 3 question fields (djlike, thinkclublike, plait). But the first review for a song from a user in a new state will have to create a new record.

So again, just to be crystal clear, the first time a user from “New York” reviews (song) “123” it will create a new record with the song id, state name, and add the review values to the 3 columns stdjlike, stthinkclublike and stplait. Next user, a different user, from NY for song “123” creates a review, it will just update the record, adding the values for stdjlike, stthinkclublike and stplait to the previous review.

I have been looking around all week and finding lots of good solutions to similar but not the same problems (A well documented solution here). I decided to go with increment because I’m updating with values that aren’t fixed numbers, I’ve been trying but I just can’t get it to work.

I started with what works. The create in the reviewstate controller saves the record when it is just a simple .new and .save. So i changed it from there to this..

def create

@reviewstate = Reviewstate.find_or_initialize_by_songid_and_state(song.id, current_user.state)
@reviewstate.stdjlike.increment!(:stdjlike, reviewstate.stdjlike)
@reviewstate.stthinkclublike.increment!(:stthinkclublike, reviewstate.stthinkclublike)
@reviewstate.stplait.increment!(:stplait, reviewstate.stplait)
@reviewstate.save!
end

Stops working. I have tried different variations and methods, this is when I feel the closest. Please help me, its been 4 days :).

Thank you in advance.

  • 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-21T11:47:07+00:00Added an answer on May 21, 2026 at 11:47 am

    If find does not return a record and a new one is initialized, stdjlike will be nil (unless you set another default value in your migration). Thus, increment will try to increment by Nil. Nil is not a fixnum though and it will not work. I suppose that this is the error you get.

    Moreover, you store your object in @reviewstate and then you refer to it by reviewstate.stdjlike. You have an instance variable @reviewstate and you then refer to the local variable reviewstate. They are two different objects.

    You should handle things differently. Check if your record exists. If yes, just get it. If not, create it. Use Reviewstate.exists?.

    Also, bear in mind that Ruby uses underscores as a convention for names. That would make it something like std_jlike or something like that. But you can always use what you feel more comfortable with.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.