Aldric,
Well, I finally had enough time to start work on it.
Let's start at the beginning.
I have to divs (imports and searchResults)
Now maybe I've changed this around a little but in the "imports" table I
added a cell after each row with...
<td><%= link_to_remote "Find Matches", :update => "projects", :url =>
{:controller => 'projects', :action => 'search', :id => import.import_id
} %></td>
This triggers the search in the "Projects Controller" for which I search
for similar unique import IDs.
-ProjectsController-
def search
import_id = params[:search]
results = Project.search_by_irb_pi(import_id, params[:page])
render :partial => 'imports/results', :locals => {:projects =>
results}
end
In the Model, I have this...
-Model-
def self.search_by_import_pi(search, page)
paginate( :per_page => 10, :page => page,
:conditions => ['import_id LIKE ?', "%#{search}%"],
:order => 'import_id ASC, pi_full_name ASC')
end
The Ajax call works fine, but the query sent to the "projects" table
looks like this...
[0;1mSELECT * FROM "projects" WHERE (import_id LIKE '%%') ORDER BY
irb_id ASC, pi_full_name ASC LIMIT 10 OFFSET 0 [0m
This will return nothing of course.
Another problem is trying to display the results in the table in the
"searchResults" div on the same page.
Thanks again
John
John Mcleod wrote:
> Whoa! There's a lot to chew on there.
> First off, thank you for the reply.
> Let me chew, chew on this over the weekend and I'll let you know my
> progress on Monday.
> I've used wil_paginate before so that helps.
> Thanks again.
> John
>
> Aldric Giacomoni wrote:
>> Hang on to your shorts - I did something quite similar.
>> It's very simple, I have two models, each are a table in a different
>> database, but when you get to Rails level, you don't care - it's just
>> two models.
>>
>> On the main page, I have two divs: patient and searchresults
>> Above the divs, I have a :
>> form_remote_tag :update => "patient", :url => { :action => "search" }
>> I use this to get a string (hint : text_field_tag is your friend)
>>
>> My controller has, for the action "search", the following:
>>
>> def search
>> name = params[:search]
>> results = GMPatient.filter_by_name(name, params[:page])
>>
>> render :partial => 'shared/paginated_gm_patients',
>> :locals => {:patients => results}
>> end
>>
>> What is "filter_by_name", you ask? Good question! I use the
>> will-paginate gem. My model has the following:
>>
>> def self.filter_by_name(search, page)
>> paginate :per_page => 20, :page => page,
>> :conditions => ['displayed_name like ?', "%#{search}%"],
>> :order => 'last ASC, first ASC'
>> end
>>
>> The '%' sign is my wildcard. So, now that I have the results, how do I
>> display them?
>>
>> It's your standard table, but here's the twist: I add a cell after the
>> data I display, and here's what's in the cell:
>> <td><%= link_to_remote "Find matches", :update => "matches", :url => {
>> :controller => "comparison", :action => "find_matches", :id =>
> ...
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---