Update not working on production environment


#1

Hi All,

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


#2

On 27 Jan 2009, at 06:43, hema gonaboina wrote:

it is not working,If the server restart it is working again upto
some requests…

My Code is

What is this - a controller action or something else ? It seems to be
insanely circular - creating a record from parameters so that you can
serialize it to xml and then deserialize it to get a hash of
attributes - really ?! SOmne of the code doesn’t even look like legal
ruby to me

Fred


#3

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

On Jan 27, 4:08 pm, Frederick C. removed_email_address@domain.invalid