I currently have a quick tool up just to get my feet wet. I think I need
some rearranging of my structure? I''ve been reading the threads on what
code goes where and how Rails should development should be done. Still a
question.
-----------------------
controllers/emaillist_controller.rb # looks correct to me
-----------------------
class EmaillistController < ApplicationController
def index
end
def build_links
if @params[''search''].length > 2
@item_result = Email.find(:all, :order_by =>
''pw_domain'',
:conditions => ["LOWER(pw_domain) LIKE ? AND pw_name !=
''postmaster'' AND
pw_name != ''spam''",
@params[''search''].downcase + ''%''])
end
end
def show
@emails = Email.find(:all, :conditions => [''client_id =
?'',
@params[:client_id]], :order => ''pw_name'')
end
end
-----------
views/emaillist/index.rhtml # uh huh, make sense here too
-----------
<h1>Find Email Account</h1>
<%= javascript_include_tag "prototype" %>
<%= javascript_include_tag "status" %>
<table width=''%75'' cellpadding=''5''
cellspacing=''5'' border=''1''>
<tr><td colspan=''2''
align=''center''><div
id=''status_id''>Status:
Complete</div></td></tr>
<tr><td>Domain: <input id=''search''
name=''search'' type=''text''
value=''''>
<%= observe_field ''search'', :frequency => 0.5, :update
=> ''target_id'',
:url => {:controller => ''emaillist'', :action =>
''build_links''}, :with =>
"''search='' + escape(value)", :loading =>
"searchStatus(''status_id'',3)",
:complete => "searchStatus(''status_id'',1)" %>
</td>
<td>
<div id=''target_id''></div>
</td></tr>
<tr><td colspan=''2''>
<div id=''results_id''></div>
</td></tr>
</table>
-----------------
views/emaillist/build_links.rhtml # questionable
-----------------
<% if @item_result %>
<% if @item_result.length > 1 && @item_result.length < 20
%>
<% for link in @item_result %>
<% linkname = '' ['' + link.pw_name +
''@'' + link.pw_domain + ''] '' %>
<%= link_to_remote linkname, :update => "results_id",
:url => {
:action => "show", :client_id => link.client_id}, :loading =>
"searchStatus(''status_id'',2)", :complete =>
"searchStatus(''status_id'',1)" %>
<% end %>
<% elsif @item_result.length > 20 %>
<%= "Too many to display" %>
<!-- code to generate links via alphabet soup here -->
<% else %>
<%= "No results" %>
<% end %>
<% else %>
<%= "Enter at least three characters to search with" %>
<% end %>
It seems I should have the build_links.rhtml code somewhere other than
the view. But I can''t figure out how I could move it to the controller.
I feel like render_partial is my friend here, but I am thinking about
this *all* wrong I suspect.
Thanks,
DAve