Topic: remote form issue: lost in parameter forest

hello again.
i've done some ajax requests with html, javascript & php before so i thought, since rails comes with a bunch of built-in ajax methods it should be easier, which it surprisingly isn't. though i've been searching all day i couldn't find any documentation on what parameters to put where and what for.

what i'm trying to do is: look for zip code, find dealer

here's my 'dealer.controller.rb':

class DealerController < ApplicationController
  scaffold:dealer
 
  def search
    @dealers=Dealer.find(:all)
  end

end

and here's my 'dealer_helper.rb':

module DealerHelper
  def validate_searchform
    zip=params[:zip].to_s
    #d=Array.new
    if zip==0
      return d
    else @dealers!=nil
      @dealers.each do |dealer|
        dealer.plz.to_s.length=zip.length
        if zip==dealer.plz
          d.push(dealer.id)
        end
      end
      return d
    end
  end
 
  def list_dealers(d)
    out=""
    if d.length!=0
      @dealers.each do |dealer|
        temp=link_to dealer.name_1, {:action => show,
          :id => dealer} + ', ' + dealer.name_2 + '<br/>' +dealer.str + ', ' +dealer.plz + ' ' +dealer.ort + '<br/><br/>'
        out+=temp
      end
      return out
    else
      out="no results"
      return out
    end
  end 
 
end

and finally my 'search.rhtml':

<html>
    <head>
        <title>search dealers</title>
        <%= javascript_include_tag "prototype" %>
    </head>
    <body>
        <h1>search dealers</h1>
        <p>zip code:</p>
       
        <% form_remote_tag :html => { :action =>
            url_for(:controller => "dealer",
            :action => "validate_searchform"),
            :update => (success="found_div", failure="error"),
            :success => "list_dealers(:action)",
            :failure => "alert('request failed')"} %>
            <%= text_field_tag("zip", "", :size=>2, :maxlength=>5) %>
            <input type="submit" value="search" />
        <% end_form_tag %>
       
        <div id="found_div"></div>
        <p><a href="/dealer/list">list all</a></p>
    </body>
</html>

any hints?

any hints on what book to buy (since all ebooks i downloaded don't contain any useful examples on how to deal with these built-in methods)?

Last edited by drumboy (2007-01-16 13:05:08)

Re: remote form issue: lost in parameter forest

You might want to check out RJS