I am very new to ruby, and trying to get auto complete / predictive text working, but I am getting the error "undefined local variable or method `providers'' " Here is the first box in my view [code] <label for="">Provider:</label> <div> <%= text_field_with_auto_complete :orders, :provider, { :tabindex => 1,:size => 30, :maxlength => 100 }, { :url => { :controller => :orders, :action => :auto_complete_for_provider_name}, :indicator => ''ajax-prov-load-ind'', :after_update_element => "function(element,value){$(''activation_customer'').enable();$(''activation_customer'').focus();}" } -%> <span style="display:none;" id="ajax-prov-load-ind"><%= image_tag ''ajax-load-ind.gif'', :style => ''vertical-align:middle;'' %></span> <a href="#TB_inline?height=350&width=400&inlineId=add_provider&modal=true" class="thickbox">Add Provider</a> </div>[/code] And here is the auto_complete_for_provider_name.rhtml, with the bold line where it throws the error. <ul> [b]<% providers.each do |key, value| -%>[/b] <li id="<%=h value -%>"><%=h key -%></li> <% end -%> </ul> here is a snippit from orders controller, def auto_complete_for_provider_name @provider = params[:orders][:provider].downcase @providers = Provider.call_provider_list_service(@provider) render :partial => ''auto_complete_for_provider_name'', :locals => {:providers => @providers} end end [/code] -- 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 -~----------~----~----~----~------~----~------~--~---
I am just lost. Can anyone tell me why I would get a undefined method undefined method `provider'' for #<Order:0x48ff74c> Extracted source (around line #16): 13: 14: <label for="">Provider:</label> 15: <div> 16: <%= text_field_with_auto_complete :order, :provider, 17: { :tabindex => 1,:size => 30, :maxlength => 100 }, 18: { :url => { :controller => :orders, 19: :action => :auto_complete_for_provider_name}, Here is the declaration of my orders controller def auto_complete_for_provider_name @provider = params[:order][:provider].downcase @providers = Provider.call_provider_list_service(@provider) render :partial => ''auto_complete_for_provider_name'', :locals => {:providers => @providers} 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 -~----------~----~----~----~------~----~------~--~---
How is your Order class setup? Does it have a provider method? In other words, does this return true in script/console: Order.new.respond_to? provider Hallik Papa wrote:> I am just lost. Can anyone tell me why I would get a undefined method > > undefined method `provider'' for #<Order:0x48ff74c> > > Extracted source (around line #16): > > 13: > 14: <label for="">Provider:</label> > 15: <div> > 16: <%= text_field_with_auto_complete :order, :provider, > 17: { :tabindex => 1,:size => 30, :maxlength => 100 > }, > 18: { :url => { :controller => :orders, > 19: :action => > :auto_complete_for_provider_name}, > > > > > Here is the declaration of my orders controller > > def auto_complete_for_provider_name > @provider = params[:order][:provider].downcase > @providers = Provider.call_provider_list_service(@provider) > render :partial => ''auto_complete_for_provider_name'', :locals => > {:providers => @providers} > 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 -~----------~----~----~----~------~----~------~--~---
If you are wanting something with the same functionality that is not designed around a specific object, you can use text_field_tag along with auto_complete_field. William Pratt wrote:> How is your Order class setup? Does it have a provider method? In other > words, does this return true in script/console: > > Order.new.respond_to? provider > > > > Hallik Papa wrote: > >> I am just lost. Can anyone tell me why I would get a undefined method >> >> undefined method `provider'' for #<Order:0x48ff74c> >> >> Extracted source (around line #16): >> >> 13: >> 14: <label for="">Provider:</label> >> 15: <div> >> 16: <%= text_field_with_auto_complete :order, :provider, >> 17: { :tabindex => 1,:size => 30, :maxlength => 100 >> }, >> 18: { :url => { :controller => :orders, >> 19: :action => >> :auto_complete_for_provider_name}, >> >> >> >> >> Here is the declaration of my orders controller >> >> def auto_complete_for_provider_name >> @provider = params[:order][:provider].downcase >> @providers = Provider.call_provider_list_service(@provider) >> render :partial => ''auto_complete_for_provider_name'', :locals => >> {:providers => @providers} >> 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 -~----------~----~----~----~------~----~------~--~---
William Pratt wrote:> How is your Order class setup? Does it have a provider method? In other > words, does this return true in script/console: > > Order.new.respond_to? providerI am not sure how to run that command. I tried it from dos prompt in project dir home doing this and didn''t seem to execute anything script:console Order.new.respond_to? provider I have changed the view to this: <%= text_field_with_auto_complete :orders, :provider, { :tabindex => 1,:size => 30, :maxlength => 100 }, { :url => { :controller => :orders, :action => :auto_complete_for_provider_name}, and the orders_controller.rb has this: def auto_complete_for_order_provider @provider = params[:order][:provider].downcase @providers = Provider.call_provider_list_service(@provider) render :partial => ''auto_complete_for_provider_name'', :locals => {:providers => @providers} end and auto_complete_for_provider_name.rhtml has this: <ul> <% providers.each do |key, value| -%> <<<<<<<<<<< NEW ERROR HERE <li id="<%=h value -%>"><%=h key -%></li> <% end -%> </ul> bringing me back to the error undefined local variable or method `providers'' Isn''t providers declared right there in the orders_controller.rb though? -- 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 -~----------~----~----~----~------~----~------~--~---
William Pratt wrote:> If you are wanting something with the same functionality that is not > designed around a specific object, you can use text_field_tag along with > auto_complete_field.This is working code in another page that I inherited to try and learn Ruby. I just started with a new object, harvesting the important code changing the method names and appropriate variables. -- 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 -~----------~----~----~----~------~----~------~--~---
Ok, here is the basic deal. The code you are using requires your Order object to have a provider method. This would be either a column in the table, an association, or possible a custom method. Based on the method you are using for autocomplete, you don''t want to use text_field_with_auto_complete, you need to use a combination of text_field_tag and auto_complete_field. You can read more about them here: http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M000610 http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptMacrosHelper.html#M000576 Hallik Papa wrote:> William Pratt wrote: > >> If you are wanting something with the same functionality that is not >> designed around a specific object, you can use text_field_tag along with >> auto_complete_field. >> > > This is working code in another page that I inherited to try and learn > Ruby. I just started with a new object, harvesting the important code > changing the method names and appropriate variables. > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
William Pratt wrote:> Ok, here is the basic deal. The code you are using requires your Order > object to have a provider method. This would be either a column in the > table, an association, or possible a custom method. Based on the method > you are using for autocomplete, you don''t want to use > text_field_with_auto_complete, you need to use a combination of > text_field_tag and auto_complete_field. You can read more about them > here: > > http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M000610 > http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptMacrosHelper.html#M000576Wonderful! Thank you. I didn''t know that a column in the table could be considered a method as well. That clears up so much. Thanks again! -- 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 10/12/07, Hallik Papa <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I am not sure how to run that command. I tried it from dos prompt in > project dir home doing this and didn''t seem to execute anything > > script:console Order.new.respond_to? providerYou do it like this: C:\myproject>ruby script/console>>The ">>" is the console prompt. Now you can enter Ruby expressions in the context of your Rails environment:>> Order.new.respond_to? :provider=> false (note that respond_to? takes a symbol, so you need ":provider", not "provider") Learn the console. Love it. :~) HTH --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
That was my bad. I should have explained the console better. Btw, respond_to? will attempt to convert it''s argument to a symbol, so anything responding to to_sym should work: >> User.new.respond_to? ''login'' => true >> User.new.respond_to? :login => true -Bill Bob Showalter wrote:> On 10/12/07, Hallik Papa <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> I am not sure how to run that command. I tried it from dos prompt in >> project dir home doing this and didn''t seem to execute anything >> >> script:console Order.new.respond_to? provider >> > > You do it like this: > > C:\myproject>ruby script/console > > > The ">>" is the console prompt. Now you can enter Ruby expressions in > the context of your Rails environment: > > >>> Order.new.respond_to? :provider >>> > => false > > (note that respond_to? takes a symbol, so you need ":provider", not "provider") > > Learn the console. Love it. :~) > > HTH > > > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 10/12/07, William Pratt <billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote:> > That was my bad. I should have explained the console better. Btw, > respond_to? will attempt to convert it''s argument to a symbol, so anything > responding to to_sym should work: > > >> User.new.respond_to? ''login'' > => true > >> User.new.respond_to? :login > => trueRight, but User.new.respond_to? login isn''t correct, and that''s what he was using. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Very true. I missed that. Have a good weekend. Bob Showalter wrote:> On 10/12/07, William Pratt <billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote: > >> That was my bad. I should have explained the console better. Btw, >> respond_to? will attempt to convert it''s argument to a symbol, so anything >> responding to to_sym should work: >> >> >> User.new.respond_to? ''login'' >> => true >> >> User.new.respond_to? :login >> => true >> > > Right, but > > User.new.respond_to? login > > isn''t correct, and that''s what he was using. > > > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---