Forum: Ruby on Rails Bizarre problems with AJAX / missing variables

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
967f758fa9de78e7fe8425469f7a7acc?d=identicon&s=25 David Barrett (Guest)
on 2005-12-23 04:52
(Received via mailing list)
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:

  <div class="form-group">
    <label for="contact_town_id">Town / Dublin area [<%= county %>|<%=
rawcode %>]:</label>
    <% 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 %>
  </div>

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

<div id="ADDLOCAL">
<% if my_country == 1 %>
<%= render :partial => 'contacts/roilocaladdress', :locals => {
:county => nil } %>
<% else %>
<%= render :partial => 'contacts/nielocaladdress', :locals => {
:county => nil } %>
<% end %>
</div>

Does anyone have any ideas?

Thanks,
David Barrett

--
Site: http://antidis.com/
967f758fa9de78e7fe8425469f7a7acc?d=identicon&s=25 David Barrett (Guest)
on 2005-12-27 02:30
(Received via mailing list)
No-one?

On 12/23/05, David Barrett <david.barrett@gmail.com> 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/
967f758fa9de78e7fe8425469f7a7acc?d=identicon&s=25 David Barrett (Guest)
on 2005-12-27 16:51
(Received via mailing list)
It's alright, it seems to have fixed itself. Seems to have been a
glitch with Textdrive.

On 12/27/05, David Barrett <david.barrett@gmail.com> 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 Barrett
> >
> > --
> > Site: http://antidis.com/
> >
>
>
> --
> Site: http://antidis.com/
>


--
Site: http://antidis.com/
This topic is locked and can not be replied to.