Saving a form using autocomplete instead of select field
Posted
by
Jason Swett
on Stack Overflow
See other posts from Stack Overflow
or by Jason Swett
Published on 2011-01-16T16:51:03Z
Indexed on
2011/01/16
16:53 UTC
Read the original article
Hit count: 226
ruby-on-rails
|forms
I have a form that looks like this:
<%= form_for(@appointment) do |f| %>
<% if @appointment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@appointment.errors.count, "error") %> prohibited this appointment from being saved:</h2>
<ul>
<% @appointment.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.fields_for @client do |client_form| %>
<div class="field">
<%= client_form.label :name, "Client Name" %><br />
<%= client_form.text_field :name %>
</div>
<% end %>
As you can see, the field for @client
is a text field as opposed to select field. When I try to save my form, I get this error:
Client(#23852094658120) expected, got ActiveSupport::HashWithIndifferentAccess(#23852079773520)
That's not surprising. It seems to me that it was expecting a select field, which it could translate into a Client
object, but instead it just got a string.
I know I can do Client.find( :first, :conditions => { :name => params[:name] } )
to find a Client
with that name, but how do I tell my form that that's what's going on?
© Stack Overflow or respective owner