# Updation not working on production environment

**URL:** <https://www.ruby-forum.com/t/updation-not-working-on-production-environment/158714>\
**Category:** Rails\
**Created:** [January 27, 2009, 7:31am UTC](https://www.ruby-forum.com/t/updation-not-working-on-production-environment/158714 "2009-01-27T07:31:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hema\_mca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@hema\_mca](https://www.ruby-forum.com/u/hema_mca)\
**Post date:** [January 27, 2009, 7:31am UTC](https://www.ruby-forum.com/t/updation-not-working-on-production-environment/158714/1 "2009-01-27T07:31:56Z")

</div>

Hi,

I am new to ruby on rails,we are developing a integrated application  
which can be accessed by many companies…

We developed application on development environment,recently we  
switched  
to production environment as per client request.The insertion operation  
working fine where are the updation not working…  
Updation working for sometimes if it is done consecutively then it is  
not  
working,If the server restart it is working again upto some requests…

My Code is

def UpdateToDB

```
    hash = params[:object].to_hash
    key = hash['key']

     if key==nil then # since 

```

the  
operation is generic  
puts " the key not coming thourgh xml"  
return nil  
end

```
     value = hash[key.to_s]

     model = hash['model']

     record = model.find(:all,:conditions=>["#{key}=?",value]) #

```

retriving the record from db

```
     updateRecord = model.new(hash['record']) # record with updated

```

fileds ,consits every filed in the record except the key value,attribute

```
    updateRecord.TimeUpdate = DateTime.now

    # Here whatever the other requirements and conversions added to 

```

the  
updateRecord and also checking the required fields to be non empty etc;

```
   recordHash = Hash.from_xml(updateRecord.to_xml)

   root = recordHash.keys
   rootElement = root(0)
    if record.update_attributes(recordHash[rootElement.to_s]) then
            puts record.to_xml
            puts "saved successfully"
            redirect_to 'index'
    end

```

end

```
           The above method working fine for updation upto some 

```

requests  
only… like 8 updates not more than… for the 9th update the statement  
record.to\_xml showing the updated value in the server but it is not get  
updated in the database…

Can anyone solve my problem and save my day…  
Thanks

---

<div class="post-metadata">

**Author:** ![hema\_mca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/779978/32.png) [@hema\_mca](https://www.ruby-forum.com/u/hema_mca)\
**Post date:** [February 4, 2009, 11:13am UTC](https://www.ruby-forum.com/t/updation-not-working-on-production-environment/158714/2 "2009-02-04T11:13:06Z")

</div>

Hi,

Here Params I given for understading purpose.this is a model code I  
am passing the params[:objects] from controller to model through  
object @objects.But,if I give that No one understands that @objects is  
getting from the veiw so I given params[:objects] in this post.(For  
understanding purpose).

The controller action

def genericCURDoperation  
companyid = session[:companyid]  
obj = MGenericCurdOperation.new(params[:objects],companyid)  
result = obj.genericAction  
puts result  
end

In my MGenericCurdOperation model

class MGenericCurdOperation  
attr\_accessor :companyid,:objects

def intialize(xml,companyid)  
@objects = xml  
@companyid = companyid  
end  
def genericAction  
hash = @objects.to\_hash  
operation = hash[‘operation’]  
if operation == “insert” then  
status = saveToDB(hash[‘record’],companyid)  
elsif operation == “update” then  
status = UpdateToDB(hash[‘record’],companyid)  
…  
end  
return status  
end

def saveToDB(record,companyid)  
…  
end

def UpdateToDB(record,companyid)

```
    hash = record.to_hash
    key = hash['key']

     if key==nil then
           puts " the key not coming thourgh xml"
           return nil
     end

     value = hash[key.to_s]

     model = hash['model']

     record = model.find(:all,:conditions=>["#{key}=?",value])

```

#retriving the record from db

```
     updateRecord = model.new(hash['record'])
 # record with updated fileds ,consits every filed in the record

```

except the key value,attribute

```
    updateRecord.TimeUpdate = DateTime.now

    # Here whatever the other requirements and conversions added

```

to the  
# updateRecord and also checking the required fields to  
be non empty etc;

```
   recordHash = Hash.from_xml(updateRecord.to_xml)

   root = recordHash.keys
   rootElement = root(0)
    if record.update_attributes(recordHash[rootElement.to_s]) then
            puts record.to_xml
            puts "saved successfully"
            redirect_to 'index'
    end

```

end  
end

this is my code with some more operations also  
if u can’t understand please look the above problem and help me
