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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedApr 9, '12 at 8:21p
activeApr 9, '12 at 8:21p
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Abram: 1 post

People

Translate

site design / logo © 2021 Grokbase