Updating two divs?

dont give a :update value.

instread, render a RJS Template in your action...

def add_address
  ... add the address to the DB etc. ...
  #at the end, the action ill automatically render the RJS template

in your controllers views directory you would have a file called

page.replace_html :div-to-update, :partial => "_address-list"
page.hide :ID-of-form-to-hide

see for more info:


-> http://api.rubyonrails.org/classes/ActionView/Base.html ...scroll
down to "JavascriptGenerator"



I am getting the XML from an external source via HTTPService post.
I am using CobraVsMongoose (CVM) to do a xml - hash conversion. One of the fields in the hash is "Task_Number", which is the id of the AR object that I want to retrive.

Here is an example of the object that CVM returns.
{"tasks"=>{"task"=>{"Task_Number"=>{"$"=>"3"}, "Task_Name"=>{"$"=>"task_three"}, "Priority_Rank"=>{"$"=>"55"}}}}

I have this code

    xml_string = params[:my_tasks]
    @my_tasks = CobraVsMongoose.xml_to_hash(xml_string)

    @my_tasks["tasks"]["task"].each do |hashed_task|
      @task = Task.find(hashed_task["Task_Number"]["$"].to_i)
      @task.priority = hashed_task["Priority_Rank"]["$"].to_f

which works perfectly when I have many tasks, however, when I am sending over only one task i get this error in the development.log
            TypeError (can't convert String into Integer):

I am pretty sure that "3".to_i should give me the integer 3. also, since the code runs smoothly for multiple tasks in the same XML document, I am baffled.

Thanks for the help

Found the problem.

When there are multiple tasks, as in this case

"Task_Name"=>{"$"=>"task_two"}, "Priority_Rank"=>{"$"=>"10"}},
{"Task_Number"=>{"$"=>"8"}, "Task_Name"=>{"$"=>"task_eight"},
"Priority_Rank"=>{"$"=>"20"}}, {"Task_Number"=>{"$"=>"4"},
"Task_Name"=>{"$"=>"task_four"}, "Priority_Rank"=>{"$"=>"30"}},
{"Task_Number"=>{"$"=>"5"}, "Task_Name"=>{"$"=>"task_five"},
"Priority_Rank"=>{"$"=>"40"}}, {"Task_Number"=>{"$"=>"1"},
"Task_Name"=>{"$"=>"task_one"}, "Priority_Rank"=>{"$"=>"50"}},
{"Task_Number"=>{"$"=>"3"}, "Task_Name"=>{"$"=>"task_three"},
"Priority_Rank"=>{"$"=>"60"}}, {"Task_Number"=>{"$"=>"7"},
"Task_Name"=>{"$"=>"task_seven"}, "Priority_Rank"=>{"$"=>"70"}},
{"Task_Number"=>{"$"=>"6"}, "Task_Name"=>{"$"=>"task_six"},

@my_tasks["tasks"]["task"] is an array of tasks, whereas in the case of
the single task, it gets parsed into a hash. My hack to fix this now is
to pass the same task twice if the number of tasks is only one, but this
is obviously a ugly hack.
Can anyone suggest how to change the rails code so that the
@my_tasks["tasks"]["task"] object looks the same, whether it has 1 or
many elements?


Ivor wrote: