user2071444
user2071444

Reputation:

fields_for part not visible in the form

Controller: project_sub_types_controller.rb

def new
    @svn_repos = ['svn_software','svn_hardware']
    @project_sub_type = ProjectSubType.new
end

Model: project_sub_type.rb

class ProjectSubType < ActiveRecord::Base
  belongs_to :project_type
  has_many :repositories, :dependent => :destroy
  accepts_nested_attributes_for :repositories
end

View: _form.html.erb

<%= form_for @project_sub_type, :html => {:class => 'project_subtype_form'} do |f| %>
  <%= f.label :name, "Project sub type name" %>
  <%= f.text_field :name %>
  <%= f.fields_for :repositories do |ff| %>
      <%= ff.label :select_svn_repositories, "Select SVN repositories" %> 
      <% @svn_repos.each do |repos| %>
          <%= ff.check_box :repos_name, {}, "#{repos}", nil %>
          <%= h repos -%>
      <% end %>
<%= f.submit "Save"%>

Question : the fields_for :repositories part is not displayed in the front end. Can anyone point out what is my mistake? Following : this link

Upvotes: 1

Views: 39

Answers (1)

sevenseacat
sevenseacat

Reputation: 25029

The @project_sub_type used to create the form doesn't have any associated repositories, therefore there are no nested fields to display on the form.

If you add one (eg. by doing @project_sub_type.repositories.build in your controller) then you will see a blank set of fields generated by the f.fields_for statement.

Upvotes: 2

Related Questions