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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:05:21+00:00 2026-06-15T20:05:21+00:00

I have written a Rails app that communities with front end by json-rpc. The

  • 0

I have written a Rails app that communities with front end by json-rpc. The ActiveRecord Class is:

class ProcessingDocument < ActiveRecord::Base
  attr_accessible :command, :comment, :creator, :emergency_level, :file_name, :is_locked, :is_removed, :last_status, :next_status, :owner_id, :paper_title, :receiver, :sender, :status, :suggest, :unit_id, :uuid, :workflow_id
  attr_accessor :command, :comment, :creator, :emergency_level, :file_name, :is_locked, :is_removed, :last_status, :next_status, :owner_id, :paper_title, :receiver, :sender, :status, :suggest, :unit_id, :uuid, :workflow_id

  def self.all_propertoes
    [:command, :comment, :creator, :emergency_level, :file_name, :is_locked, :is_removed, :last_status, :next_status, :owner_id, :paper_title, :receiver, :sender, :status, :suggest, :unit_id, :uuid, :workflow_id]
  end
end

And the Controller dynamic updates the object of ProcessingDocument by json.

def pd_create(json)
    pd_now = ProcessingDocument.new(:uuid => generate_uuid)
    json["params"].each do |k, v|   # the json["params"] is a Hash
        if ProcessingDocument.all_propertoes.include? k.to_sym
            pd_now.send("#{k}=", v)
        else
            render json: default_fail_json(json, __method__)
            return
        end
    end

    if pd_now.save
        debug_method pd_now.to_json  # this is a stdout bebug

        result = { :uuid => pd_now.uuid }
        render json: respond_data(json, result, nil)
    else
        render json: default_fail_json(json, __method__)
    end
end

When I post a json {"status":"1", "command":"stuff"}, the debug_method print:

{"command":"stuff","comment":null,"created_at":"2012-12-11T12:02:41Z",
"creator":null,"emergency_level":null,"file_name":null,"id":16,"is_locked":null,
"is_removed":null,"last_status":null,"next_status":null,"owner_id":null,
"paper_title":null,"receiver":null,"sender":null,"status":"1","suggest":null,
"unit_id":null,"updated_at":"2012-12-11T12:02:41Z",
"uuid":"21403d30-c2c1-4fc8-94ba-36d059fdc170","workflow_id":null}

But the database don’t save the “command”, ,”status” and “uuid” :

Started POST "/services/" for 127.0.0.1 at 2012-12-11 20:02:41 +0800
Processing by ServicesController#accept as JSON
Parameters: {"{\"id\":\"7e330302-dede-4d2f-bf52-8e90174bb837\",\"method\":\"pd_create\",\"params\":{\"status\":\"1\",\"command\":\"stuff\"}}"=>nil}
(0.0ms)  begin transaction
SQL (0.5ms)  INSERT INTO "processing_documents" ("command", "comment", "created_at", "creator", "emergency_level", "file_name", "is_locked", "is_removed", "last_status", "next_status", "owner_id", "paper_title", "receiver", "sender", "status", "suggest", "unit_id", "updated_at", "uuid", "workflow_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["command", nil], ["comment", nil], ["created_at", Tue, 11 Dec 2012 12:02:41 UTC +00:00], ["creator", nil], ["emergency_level", nil], ["file_name", nil], ["is_locked", nil], ["is_removed", nil], ["last_status", nil], ["next_status", nil], ["owner_id", nil], ["paper_title", nil], ["receiver", nil], ["sender", nil], ["status", nil], ["suggest", nil], ["unit_id", nil], ["updated_at", Tue, 11 Dec 2012 12:02:41 UTC +00:00], ["uuid", nil], ["workflow_id", nil]]
(2.5ms)  commit transaction
Completed 200 OK in 23ms (Views: 0.2ms | ActiveRecord: 3.5ms)

You have see the SQL :SQL (0.5ms) INSERT INTO "processing_documents" ("command", "comment", "created_at", "creator", "emergency_level", "file_name", "is_locked", "is_removed", "last_status", "next_status", "owner_id", "paper_title", "receiver", "sender", "status", "suggest", "unit_id", "updated_at", "uuid", "workflow_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [["command", nil], ["comment", nil], ["created_at", Tue, 11 Dec 2012 12:02:41 UTC +00:00], ["creator", nil], ["emergency_level", nil], ["file_name", nil], ["is_locked", nil], ["is_removed", nil], ["last_status", nil], ["next_status", nil], ["owner_id", nil], ["paper_title", nil], ["receiver", nil], ["sender", nil], ["status", nil], ["suggest", nil], ["unit_id", nil], ["updated_at", Tue, 11 Dec 2012 12:02:41 UTC +00:00], ["uuid", nil], ["workflow_id", nil]]

  • 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-15T20:05:22+00:00Added an answer on June 15, 2026 at 8:05 pm

    Why do you call attr_accessor on your model attributes?

    attr_accessor :command, :comment, :creator, :emergency_level, :file_name, :is_locked, :is_removed, :last_status, :next_status, :owner_id, :paper_title, :receiver, :sender, :status, :suggest, :unit_id, :uuid, :workflow_id
    

    These are creating accessor methods which set instance variables, e.g. attr_accessor :command does the equivalent of creating a method like this:

    def command
      @command
    end
    
    def self.command=(value)
      @command = value
    end
    

    So what is happening in your code right now is that when you call pd_now.send("#{k}=", v) on each key/value in the hash, instance variables are being set rather than database attributes. That is why you are not seeing the attributes in the SQL generated after you call save.

    To fix this, just remove the attr_accessor line in your model.

    Ref: Why use Ruby's attr_accessor, attr_reader and attr_writer?

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

Sidebar

Related Questions

Im developing a Rails app that will contain a web front end as well
I have some additional scripts that I've written outside of my Rails 3.1.x app,
I have written constant.rb in lib/ folder for my rails app.To use that in
I have a roles model in a rails app that I have written a
I have built a simple rails app with three classes that inherit from ActiveRecord
I have written the following code in my Rails app to generate XML. I
I've written a rails app that follows the regular directory structure (model code in
I have written a small rails app to serve up content to another site
I have a Ruby on Rails app that works fine locally with a sqlite3
I have a rails app, that is setup with the default test unit, how

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.