# Variable not being populated?

**URL:** <https://www.ruby-forum.com/t/variable-not-being-populated/117552>\
**Category:** Rails\
**Created:** [October 18, 2007, 12:07am UTC](https://www.ruby-forum.com/t/variable-not-being-populated/117552 "2007-10-18T00:07:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hallikpapa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/90db22/32.png) [@hallikpapa](https://www.ruby-forum.com/u/hallikpapa)\
**Post date:** [October 18, 2007, 12:07am UTC](https://www.ruby-forum.com/t/variable-not-being-populated/117552/1 "2007-10-18T00:07:51Z")

</div>

I have this order form that auto populates these fields as you step  
through  
provider:  
customer:  
location:  
device:

Provider field works great, and then I move to Customer. I need to  
capture the providerId from the previous query (although it displays  
provider name, the XML returns the Id as well), and use it to do a look  
up on customers (SELECT \* FROM Customers where providerId = ?). Where am  
I going wrong?

but my params[providerId] is blank. Here is the provider and customer  
sections in the orderscontroller.rb

def auto\_complete\_for\_provider\_order  
@provider = params[:order][:provider].downcase  
@providers = Provider.call\_provider\_list\_service\_order(@provider)

```
render :partial => 'auto_complete_for_provider_order', :locals =>

```

{:providers =\> @providers}  
end

def auto\_complete\_for\_customer\_service\_order  
@customer = params[:order][:customer].downcase  
@provider = params[:order][:provider].downcase  
@provider\_id = params[:providerId]  
@customers =  
Customer.call\_customer\_list\_service\_order(@provider\_id)  
render :partial =\> ‘auto\_complete\_for\_customer\_service\_order’,  
:locals =\> {:customers =\> @customers}  
end

Here is my provider.rb model

def self.call\_provider\_list\_service\_order(provider = ‘’)  
xml = “”

```
  x = Builder::XmlMarkup.new(:target => xml)
  x.instruct!
   x.Automanager("xmlns:xsi" =>

```

“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”) {  
x.request {  
x.header {  
x.logonid “xxx”  
x.password “yyy”  
x.version “1.3”  
x.requestType “getProviderList”  
}  
x.body {  
x.getProviderList {  
} # end getProviderList  
} # end body  
} # end request  
} # end Automanaager

```
result = post(xml)

doc = REXML::Document.new result.body
providers = {}

provider_nodes = REXML::XPath.each( doc, "//provider" ) do |element|
  if element.elements["name"].text.downcase

```

=~/^#{provider.downcase}/  
providers[element.elements[“name”].text]=element.elements[“providerId”].text  
end  
end  
providers  
end

And here is my customer.rb model

def self.call\_customer\_list\_service\_order(provider)  
xml = “”  
x = Builder::XmlMarkup.new(:target =\> xml)  
x.instruct!  
x.Automanager(“xmlns:xsi” =\>  
“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”) {  
x.request {  
x.header {  
x.logonid “xxx”  
x.password “yyy”  
x.version “1.3”  
x.requestType “getCustomerList”  
}  
x.body {  
x.getCustomerList {  
x.providerId provider  
} # end getCustomerList  
} # end body  
} # end request  
} # end Automanaager

```
result = post(xml)

doc = REXML::Document.new result.body
customers = {}

customer_nodes = REXML::XPath.each( doc, "//customer" ) do |element|
  if element.elements["name"].text =~/^#{@customer}/
    customers[element.elements["name"].text]=element.elements["customerId"].text
  end
end
customers

```

end
