Sharing data in a form between new and edit using partial

This is pretty basic 

if you want to share a field name in account object then you would create a partial called _account

and will have to pass the form field as locals to the render call. Othewise you will not be able to use the data between new and update

Update

<% form_for :account, @account, :url => { :action => “update” } do |f| %>
  <%= f.error_messages %>
 
      <%= render :partial =>’account’, :locals=>{:f=>f} %>
     <%= f.submit ‘Save’ %>

<% end %>

New

<% form_for :emergency_profile, @emergency_profile, :url => { :action => “create” } do |f| %>
  <%= f.error_messages %>
 
      <%= render :partial =>’profile’, :locals=>{:f=>f} %>
     <%= f.submit ‘Save’ %>

<% end %>

Note the locals being passed in both

Now the partial _account.html.erb looks like

  <p><label for=”account_number”> Account Number:</label></p> <%=f.text_field:account_number,:size =>20%>

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s