Bizarre problems with AJAX / missing variables

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/

No-one?

On 12/23/05, David B. [email protected] 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/


Site: http://antidis.com/

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

On 12/27/05, David B. [email protected] 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/


Site: http://antidis.com/


Site: http://antidis.com/