I am trying to rewrite my website in Rails 3 and Ruby 1.9.2.
Can some one help me convert my observe_field which is working under
Rails 2.3.5 to Rails 3. I would like to avoid using JQuery as over the
last year everything I have tried in JQuery has failed, including this
one. Perhaps due to my lack of knowledge. I would not like to install
the legacy upgrade.
What I have in my website is several pages(models) which use the same
search text field. Each controller has an action "search" which
renders a partial "_searchresults" on the page with the text field.
The code which works well in Rails 2.3.5 along with one typical
example search action from a controller and the "_searchresults" is
shown below:-
In the searches index.heml.erb:-
***************************************...........
<p align="center"><font
color="blue"><b>Just type the word or part
of the word and wait two seconds</b></font></p><br/>
<% if params[:area] != nil%>
<% form_tag({:action => "foo"},{:id => "search"})
do %>
<%= label_tag(:query, "Search for:") %>
<%= text_field_tag("query", params[:query], :autocomplete
=>
"off" , :onKeyPress=>"return disableEnterKey(event)")
%>
<% end %>
<%= observe_field ''query'', :frequency => 2,
:update => "search_results",
:url => {:controller => params[:area], :action =>
"search",:area => params[:area]},
:method=>:get,
:with => "query" %>
<div id="search_results">
<p class="plantname2">(Search results will be listed
here)</p>
<%end%>
</div>
<%= set_focus_to_id ''query'' %>
In one of the controller:-
******************************...........
def search
session[:query] = params[:query].strip if params[:query]
if session[:query] and request.xhr?
@plants_sn = Plant.find(:all, :conditions => ["scientificname
LIKE ?", "%#{session[:query]}%"], :order => "commonname
ASC")
@plants_cm =Plant.find(:all, :conditions => ["commonname LIKE
?",
"%#{session[:query]}%"], :order => "commonname ASC")
@plants_desc =Plant.find(:all, :conditions => ["description
LIKE ?", "%#{session[:query]}%"], :order => "commonname
ASC")
@plants = (@plants_cm + @plants_sn + @plants_desc).uniq
render :partial => "shared/searchresults", :layout =>
false, :locals => {:searchresults => @plants}
end
end
In Views/Shared/_searchresults:-
**********************............
<% if searchresults.length == 0 %>
<p>Sorry! No articles found...</p>
<% elsif params[:query] == "" %>
<p>You must enter a search term.</p>
<% else %>
<% if params[:area] == "plants" %>
<table>
<tr>**************.............elseif,elsfif etc,etc.
*******************************************************************
At the moment I am trying with a submit_tag, but I am getting a
missing template error. So I must solve this before I can continue
with the observe field.:-
<% end %>
<p align="center"><font
color="blue"><b>Just type the word or part of
the word and wait two seconds</b></font></p><br/>
<% if params[:area] != nil%>
<% form_tag url_for({:controller => params[:area], :action
=> :search, :area => params[:area] }), :method => "get",
:remote =>
true do %>
<%= label_tag(:query, "Search for:") %>
<%= text_field_tag("query", params[:query], :autocomplete =>
"off" , :onKeyPress=>"return disableEnterKey(event)")
%>
<%= submit_tag("Search", :name => nil) %>
<% end %>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.