Women in Technology

Hear us Roar



Article:
  Ajax on Rails
Subject:   access from controller for :searchtext
Date:   2005-06-28 19:42:26
From:   vcosby
I'm trying out the observer example, but can't seem to get at the :searchtext observed value from the controller.

# this don't work
def live_search
render_text "return search results using " +
params[:searchtext]
end
Full Threads Oldest First

Showing messages 1 through 6 of 6.

  • access from controller for :searchtext
    2005-07-27 07:33:31  k.y.l.e [View]

    Just add :with => "'searchtext='+value'" to the observe_field call in the view.

    <%= observe_field(:searchtext,
    :frequency => 0.25,
    :update => :search_hits,
    :with => "'searchtext='+value",
    :url => { :action => :live_search }) %>
  • Curt Hibbs photo access from controller for :searchtext
    2005-06-29 05:28:27  Curt Hibbs | O'Reilly AuthorO'Reilly Blogger [View]

    "params" is an instance variable, so you need to prefix it with an at-sign:

    @params[:searchtext]
    • access from controller for :searchtext
      2005-06-29 21:43:10  vcosby [View]

      Thanks for your help, but I'm still getting nil for the param value.

      Here's the code. Even tried adding a form tag around it, but no luck.

      index.rhtml:

      <form action="/demo" method="get">
      <label for="searchtext">Live Search:</label>
      <%= text_field_tag :searchtext %>
      </form>
      <%= observe_field(:searchtext,
      :frequency => 1,
      :url => { :controller => "demo",
      :action => :live_search },
      :update => "search_hits") -%>

      Search Results:


      <div id="search_hits"></div>


      demo_controller.rb

      def live_search
      render_text @params[:searchtext]
      end
      • access from controller for :searchtext
        2005-06-29 22:14:32  vcosby [View]

        aha!
        maybe the api changed. it appears you have to grab it from the request's raw post or querystring.


        def live_search
        render_text "you searched for: " +
        request.raw_post || request.query_string
        end

        • access from controller for :searchtext
          2005-10-10 11:11:52  mewren.com [View]

          I had the same problem. I had forgotten to include the library
          <%= javascript_include_tag "prototype" %>
          • access from controller for :searchtext
            2005-12-09 12:21:43  kevinmarshall [View]

            I was having a little trouble getting this to work too...so I added in a VERY generic test...ad in

            render_text @params.inspect

            This will show you all the fields you can access via the params ... you'll probably notice that the searchtext isn't listed, but rather the value you entered is being put there (at least that was my case) ... using the :with => "'searchtext='+value" mentioned above solved my problem ... but I thought it was worth mentioning this simple debugging approach for params