Helpful Information
 
 
Category: Ruby Programming
Undefined local variable or method

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


<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>



And here is the auto_complete_for_provider_name.rhtml, with the bold line where it throws the error.


<ul>
<% providers.each do |key, value| -%>
<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

Humm, in your view, you may need to:

@providers.each do |blahblahblah|

I was thinking this was like java. I did not know a column in a table could be considered a method. Added a provider column and boosh! It started working.










privacy (GDPR)