I have a form for submission of brand, model, and style. Style
belongs_to model, and model belongs_to brand. The form is actually a
style submission form, but allows users to create new brands or models
as well, should they not exist.
What I want is for the autocomplete for ''model'' to populate
when an
object for ''brand'' is selected in the first text field..
..and so on for submodel...
I have the following autocomplete field for brand
<%= form_for @style, :html => { :class =>
''form-horizontal'' } do |f| %>
<fieldset>
<legend></legend>
<div class="control-group">
<%= f.label :brand_name, :class => ''control-label''
%>
<div class="controls">
<%= f.text_field :brand_name, data: {autocomplete_source:
brands_path}, :class => ''text_field'' %>
</div>
</div>
<div class="form-actions">
<%= f.submit nil, :class => ''btn btn-primary''
%>
<%= link_to ''Cancel'', styles_path, :class =>
''btn'' %>
</div>
</fieldset>
<% end %>
and in styles.rb (model):
belongs_to :brand
def brand_name
brand.try(:name)
end
def brand_name=(name)
self.brand = Brand.find_or_create_by_name(name) if name.present?
end
and in styles.js.coffeescript:
jQuery ->
$(''#style_brand_name'').autocomplete
source:
$(''#style_brand_name'').data(''autocomplete-source'')
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.