I got a form that have a nested link. The problem that the link field is empty on edit.
Here is my form:
<h1>Editing kategori</h1>
<%= simple_form_for(@konkurrancer, :url => {:action => 'update', :id => @konkurrancer.id }) do |f| %>
<%= f.simple_fields_for :link_attributes do |d| %>
<%= d.input :link, :label => 'Tracking url', :style => 'width:500;' %>
<% end %>
<%= f.button :submit, :value => 'Edit konkurrence' %>
<% end %>
<%= link_to 'Show', admin_konkurrancer_path %> |
<%= link_to 'Back', admin_konkurrancer_path %>
My konkurrencer model:
has_one :link
My link model:
class Link < ActiveRecord::Base
belongs_to :konkurrancer
accepts_nested_attributes_for :konkurrancer
end
My konkurrancer edit action:
def edit
@konkurrancer = Konkurrancer.find(params[:id])
@konkurrancer.link_attributes.build
end
1) Remove from your Link model
and add to your Konkurrancer model
2) In controller edit action remove
and in controller new action add
3) In the view file replace
with