Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

RJS generating raw javascript when using observe_field

#1124

Hi, I'm in the process of structuring a live search within an application. Thus, I have the following so far:

  • search.html.erb - This file contains the entire template for the page. The relevant pieces is as follows:

<%= text_field_tag 'search_text' %>

<%= observe_field( 'search_text',

                                :frequency => 0.5,
                    :with => 'search_text',
                                :url => { :action => :search }) %>

  • UpdateController#search - The relevant pieces is as follows:

def search

@episodes = Episode.activated.search( params[:search_text] )

render :update do | page |
  page[:search_hits].replace_html :partial => 'episode', :collection => @episodes, :locals => { :display => "thumb" }
end

end

Now, when render is invoked in the search action above, I'm getting the raw Javascript code returned to the browser in a try-catch block instead of the search_hits div being updated. Lastly, I'm using Rails 2.1.1 on Mac OS X 10.5.5.

Reported by Conrad Taylor · September 27th, 2008 @ 01:22 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. eknv
    eknv

    I also had the try-catch issue, my javascript codes were just displayed instead of getting executed.

    Wrapping the rjs code with a javascript content-type header made it work:

    page << ' '

    September 29th, 2008 @ 04:12 PM

  2. Pratik
    Pratik
    • Tag changed from 2.1, bug, rjs to 2.1, bug, rjs
    • State changed from new to invalid

    You should ask this on the mailing list - http://groups.google.com/group/r...

    Thanks.

    January 18th, 2009 @ 05:49 AM