Rails populate edit form for non-column attributes

Posted by Rabbott on Stack Overflow See other posts from Stack Overflow or by Rabbott
Published on 2011-02-19T23:21:01Z Indexed on 2011/02/19 23:25 UTC
Read the original article Hit count: 225

Filed under:
|

I have the following form:

<% form_for(@account, :url => admin_accounts_path) do |f| %>
  <%= f.error_messages %>

    <%= render :partial => 'form', :locals => {:f => f} %>

    <h2>Account Details</h2>
    <% f.fields_for :customer do |customer_fields| %>
    <p>
        <%= customer_fields.label :company %><br />
        <%= customer_fields.text_field :company %>
    </p>
    <p>
        <%= customer_fields.label :first_name %><br />
        <%= customer_fields.text_field :first_name  %>
    </p>
    <p>
        <%= customer_fields.label :last_name %><br />
        <%= customer_fields.text_field :last_name  %>
    </p>
    <p>
        <%= customer_fields.label :phone %><br />
        <%= customer_fields.text_field :phone  %>
    </p>
    <% end %>

  <p>
    <%= f.submit 'Create' %>
  </p>
<% end %>

As well as

attr_accessor :customer

And I have a before_create method for the account model which does not store the customer_fields, but instead uses them to submit data to an API.. The only thing I store are in the form partial..

The problem I'm running into is that when a validation error gets thrown, the page renders the new action (expected) but none of the non-column attributes within the Account Detail form will show?

Any ideas as to how I can change this code around a bit to make this work me??

This same solution may be the help I need for the edit form, I have a getter for the data which it asks the API for, but without place a :value => "asdf" within each text box, it doesn't populate the fields either..

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about forms