I’m trying to create a search on the index page where it will take a
search input and return to the same page. On this page is a list of
all the search items. So I want to highlight them all with AJAX and
then leave then in bold permanently. The problem comes in evaluating
the school and search term. I really have no idea what I’m doing with
this.
page.select("#alphabet strong").each do |element|
element.visual_effect :highlight if @search.include? school
element.insert_html make bold
end
Search schools
<% form_remote_tag :url => { :action => 'result' } do %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
<% end %>
Listing Schools
<% 'a'.upto 'z' do |l| %>
<%= l %>
<% for school in @schools %>
<% if school.title.first == l.upcase %>
<%= link_to h (school.title),
new_school_course_path(school) %>
<% end %>
<% end %>
<% end %>
sounds like you should be using setStyle (a prototype method) to make
your elements bold, e.g.:
element.setStyle({fontWeight: ‘bold’})
I’m not sure if there’s an RJS wrapper for the setStyle method so I’m
not entirely sure this will work as written. Something like this will
definitely work though:
page << “$(#{element}).setStyle({fontWeight:‘bold’});”
… which is kinda the long way around.
It does not work for some reason…
page[‘element’].setStyle({fontWeight: ‘bold’})
On Dec 19, 2007 4:20 PM, edberner [email protected] wrote:
not entirely sure this will work as written. Something like this will
all the search items. So I want to highlight them all with AJAX and
<% form_remote_tag :url => { :action => ‘result’ } do %>
–
Ryan B.
I’m not sure this is the code I’m looking for because I’ve tried every
combination of ‘element’ including
#alphabet dd
alphabet dd
alphabet
and none of those elements work to change the div. More importantly,
shouldn’t this change the entire div? I would like to only change
those that match the search results. My index has two arrays for all
schools and the search results @search. Is there really just no way to
pass this to javascript for ajax? Would that be useful? Is what I’m
implementing just too ridiculous?