# Bizarre problems with AJAX / missing variables

**URL:** <https://www.ruby-forum.com/t/bizarre-problems-with-ajax-missing-variables/50960>\
**Category:** Rails\
**Created:** [December 23, 2005, 4:52am UTC](https://www.ruby-forum.com/t/bizarre-problems-with-ajax-missing-variables/50960 "2005-12-23T04:52:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [December 23, 2005, 4:52am UTC](https://www.ruby-forum.com/t/bizarre-problems-with-ajax-missing-variables/50960/1 "2005-12-23T04:52:40Z")

</div>

I’m having some really weird problems with an app I’m writing.

Everything is working as expected on my development machine (OSX,  
Rails 0.14.4) but is cacking out with weird errors on the Textdrive  
demo site (FreeBSD, Rails 1.0.0). It complains about missing  
variables, with errors like this:

undefined local variable or method `rawcode’ for  
#\<#Class:0x8efa1ec:0x8efa138\>

This was when I added in rawcode to the locals for the partial for  
debugging. Again, everything works fine on the development machine,  
and I get the rawcode displayed in the browser as expected.

At one stage I had the following code:

\<% unless county.nil? %\>  
foo  
\<% else %  
bar  
\<% end %\>

…and I didn’t assign county a value at all if I didn’t know it. I  
checked to see if county was set by checking if it was nil. When I  
first noticed it was giving me problems on the demo server, I  
explicitly set it to nil (see the code for the last partial listed)  
and that stopped the error; but now it didn’t seem to be picking up  
any changes to the local variable ‘county’ (again, still working as  
expected on my development machine).

It doesn’t seem that the county variable is being set. Here is the  
code for the relevant AJAX action:

def localform  
rawcode = request.raw\_post || request.query\_string  
@county = County.find( rawcode.sub( /^(\d+)\D.\*$/ ) { |s| $1 } )  
if ( @county.country.code == “IE” )  
render :partial =\> “roilocaladdress”, :layout =\> false, :locals  
=\> { :county =\> @county.id, :rawcode =\> rawcode }  
else  
render :partial =\> “nielocaladdress”, :layout =\> false  
end  
end

and the relevant code for the contacts/roilocaladdress partial:

 Town / Dublin area [\<%= county %\>|\<%= rawcode %\>]: \<% unless county.nil? %\> \<%= select('contact', 'town\_id', Town.find(:all, :conditions =\> ['county\_id = ?', county] ).collect {|t| [t.name, t.id] }, { :include\_blank =\> true }) %\> \<% else %\> \<%= select('contact', 'town\_id', Town.find\_all.collect {|t| [t.name + ", Co. " + t.county.name, t.id] }, { :include\_blank =\> true }) %\> \<% end %\> 

and the relevant code for the parent partial, contacts/irishaddress:

\<% if my\_country == 1 %\> \<%= render :partial =\> 'contacts/roilocaladdress', :locals =\> { :county =\> nil } %\> \<% else %\> \<%= render :partial =\> 'contacts/nielocaladdress', :locals =\> { :county =\> nil } %\> \<% end %\>

Does anyone have any ideas?

Thanks,  
David B.

–  
Site: [http://antidis.com/](http://antidis.com/)

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [December 27, 2005, 2:30am UTC](https://www.ruby-forum.com/t/bizarre-problems-with-ajax-missing-variables/50960/2 "2005-12-27T02:30:52Z")

</div>

No-one?

On 12/23/05, David B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## debugging. Again, everything works fine on the development machine, …and I didn’t assign county a value at all if I didn’t know it. I def localform and the relevant code for the contacts/roilocaladdress partial: t.name + ", Co. " + t.county.name, t.id ] }, { :include\_blank =\> true \<% else %\>
> 
> Site: [http://antidis.com/](http://antidis.com/)

–  
Site: [http://antidis.com/](http://antidis.com/)

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [December 27, 2005, 4:51pm UTC](https://www.ruby-forum.com/t/bizarre-problems-with-ajax-missing-variables/50960/3 "2005-12-27T16:51:42Z")

</div>

It’s alright, it seems to have fixed itself. Seems to have been a  
glitch with Textdrive.

On 12/27/05, David B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > undefined local variable or method `rawcode’ for #\<#Class:0x8efa1ec:0x8efa138\>  
> > bar  
> > It doesn’t seem that the county variable is being set. Here is the  
> > end  
> > :include\_blank =\> true }) %\>  
> > \<% if my\_country == 1 %\>  
> > Thanks,  
> > David B.
> > 
> > –  
> > Site: [http://antidis.com/](http://antidis.com/)
> 
> –  
> Site: [http://antidis.com/](http://antidis.com/)

–  
Site: [http://antidis.com/](http://antidis.com/)
