Hi, I have 2 tables such as: create_table "professionals" do |t| t.integer "user_id" t.string "telephone" end create_table "users" do |t| t.string "nicename" end ...and I would like to edit the auto_complete_for line to include the professionals table, in order to only find nicename of professionals user. class ProfessionalsController < ApplicationController auto_complete_for :user, :nicename, :limit => 15, :order => ''nicename DESC'' (...) end Is that possible to joint the professionals table by using :conditions for example ? Thanks for any help. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, Jun 29, 2008 at 11:22 AM, David B. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have 2 tables such as: > > create_table "professionals" do |t| > t.integer "user_id" > t.string "telephone" > end > > create_table "users" do |t| > t.string "nicename" > end > > ...and I would like to edit the auto_complete_for line to include the > professionals table, in order to only find nicename of professionals > user. > > class ProfessionalsController < ApplicationController > auto_complete_for :user, :nicename, :limit => 15, :order => ''nicename > DESC'' > (...) > end > > Is that possible to joint the professionals table by using :conditions > for example ?You can write your own auto completion method: def auto_complete_for_user_nicename @users = ... render :inline => ''<%= auto_complete_result @users, :nicename %>'' 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Xavier Noria wrote:>> Is that possible to joint the professionals table by using :conditions >> for example ? > > You can write your own auto completion method: > > def auto_complete_for_user_nicename > @users = ... > render :inline => ''<%= auto_complete_result @users, :nicename %>'' > endI don''t really see how to use this method. I also had trying to joint the professionals table with this: auto_complete_for :user, :nicename, :limit => 15, :order => ''nicename, :include => :professionals but that do not work because I just can add a :conditions option. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, Jun 29, 2008 at 12:26 PM, David B. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Xavier Noria wrote: >>> Is that possible to joint the professionals table by using :conditions >>> for example ? >> >> You can write your own auto completion method: >> >> def auto_complete_for_user_nicename >> @users = ... >> render :inline => ''<%= auto_complete_result @users, :nicename %>'' >> end > > I don''t really see how to use this method. I also had trying to joint > the professionals table with this: > auto_complete_for :user, :nicename, :limit => 15, :order => ''nicename, > :include => :professionals > but that do not work because I just can add a :conditions option.The auto_complete_for macro just generates a method with that name. You need to *remove* the macro and *implement* the method. Your custom action auto_complete_for_user_nicename typically takes what the user has typed from the params hash and issues a custom query. If you trace Ajax calls with firebug you''ll see auto completion just invokes that action (by default). In the action you are free to do anything to figure out the completions and send the results back to the browser. Once you have the collection in @users the auto_complete_result helper eases building the results the way the client expects them. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Xavier Noria wrote:> The auto_complete_for macro just generates a method with that name. > > You need to *remove* the macro and *implement* the method. Your custom > action auto_complete_for_user_nicename typically takes what the user > has typed from the params hash and issues a custom query. If you trace > Ajax calls with firebug you''ll see auto completion just invokes that > action (by default). In the action you are free to do anything to > figure out the completions and send the results back to the browser. > > Once you have the collection in @users the auto_complete_result helper > eases building the results the way the client expects them.Thanks a lot. Now it''s okay ;) If that could be useful, I copy past my method: def auto_complete_for_user_nicename @users = User.find(:all, :include => :professional, :conditions => [''user_id > ? and nicename LIKE ?'', 0, "%#{params[:user][:nicename]}%"]) render :inline => ''<%= auto_complete_result @users, :nicename %>'' end -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---