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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:04:47+00:00 2026-05-25T02:04:47+00:00

I’m having a strange issue here – I’m either sending the attributes wrong, or

  • 0

I’m having a strange issue here – I’m either sending the attributes wrong, or I’m doing something wrong on the Rails end. It looks like there’s more to do wrong on the javascript/jQuery side of things than the Rails side of things, so that one is more likely.

Anyways, here are the relevant pieces of code. My question is on the very bottom of this post.

The Controller Method

  def update
    @answer = Answer.find(params[:id])
    @answer.update_attributes(params[:answer])
    puts @answer.inspect
    respond_to do |format|
      format.html { render :json => Answer.find(params[:id]) }
    end
  end

The Javascript Function (jQuery is loaded)

function saveAnswer(question_number, answer_number)
{
    console.log(JSON.stringify(window.questions[question_number].answers[answer_number]));
    $.ajax(
    {
        type: 'POST',
        url: "/answers/" + window.questions[question_number].answers[answer_number].id + "/update",
        data: JSON.stringify(window.questions[question_number].answers[answer_number]),
    });
}

The Output of the above console.log() function being called:

{"content":"Latte.ASDASD!!!!       Z","created_at":"2011-08-15T20:01:48Z","graded":true,"id":9,"problem_id":2,"turned_in":true,"updated_at":"2011-08-22T06:42:20Z","user_id":1,"score":5}

WEBrick receiving the request:

Started POST "/answers/9/update" for 127.0.0.1 at 2011-08-21 23:44:10 -0700
  Processing by AnswerController#update as */*
  Parameters: {"content"=>"Latte.ASDASD!!!!       Z", "created_at"=>"2011-08-15T20:01:48Z", "graded"=>"true", "id"=>"9", "problem_id"=>"2", "turned_in"=>"true", "updated_at"=>"2011-08-22T06:42
:20Z", "user_id"=>"1", "score"=>"5"}
  ←[1m←[36mAnswer Load (0.0ms)←[0m  ←[1mSELECT "answers".* FROM "answers" WHERE "answers"."id" = ? LIMIT 1←[0m  [["id", "9"]]
  ←[1m←[35mCACHE (0.0ms)←[0m  SELECT "answers".* FROM "answers" WHERE "answers"."id" = ? LIMIT 1
Completed 200 OK in 16ms (Views: 4.9ms | ActiveRecord: 0.0ms)

The Model’s Contents:

irb(main):007:0> Answer.inspect
    => "Answer(id: integer, problem_id: integer, user_id: integer, content: text, created_at: datetime, updated_at: datetime, turned_in: boolean, graded: boolean)"

How do I get Rails to update the attributes of the specified Answer model using the input from the saveAnswer function?

  • 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-25T02:04:48+00:00Added an answer on May 25, 2026 at 2:04 am

    You’re missing the root element in the data field of your JSON request. Should be like:

    function saveAnswer(question_number, answer_number) {
      console.log(window.questions[question_number].answers[answer_number]);
    
      $.ajax({
        type: 'POST',
        url: "/answers/" + window.questions[question_number].answers[answer_number].id + "/update",
        data: { answer: window.questions[question_number].answers[answer_number] }
      });
    }
    
    • 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
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.