Search code examples
ruby-on-railssimple-formnested-attributes

No input found for varchar


I am trying use nested models in my rails application but I have a little issue.

This is my view:

<%= simple_form_for @installation do |f| %>
  <div class="field">
    <%= f.label :x %><br>
    <%= f.input :x %>
  </div>

  <%= f.simple_fields_for :address do |u| %>
    <div class="field">
      <%= u.label :street_address %><br>
      <%= u.input_field :street_address %>
    </div>
  <% end %>

<% end %>

When I run, I receive this error <%= u.input_field :street_address %> -> "No input found for varchar", but when I change this peace of code to <%= u.input_field :street_address, :as => :string %> work. Why this happen?


Solution

  • The magic is simple form will automatic detect your data type and automatically pick a input control for it. For instance:

    text => text_area
    string => text field
    boolean => checkbox
    

    As the document described, there is not data type of varchar that simple form can understand autotically, so you need to specify the input type manually!

    So you can use as: :string or as: :text to make it work!