Model is
has_many :questions
accepts_nested_attributes_for :questions
Controller
params.require(:survey).permit(:title,:description,questions_attributes: [:title])
View is
<%= f.fields_for :questions,@survey.questions.build do |question| %>
<div class="form-group">
<label class="col-lg-12 control-label" for="">Title</label>
<p><%= question.text_field :title %></p>
</div>
<% end %>
By this I only enter question just for one time.How I add multiple times question in it.I cant understand either I do it with JavaScript and make any button or which way I do this?
You can add multiple questions by using "nested_form" gem like this:-
# Add gem in Gemfile and run bundle install
gem "nested_form"
In view:-
<%= nested_form_for @survey do |f| %>
<%= f.fields_for :questions do |question| %>
<div class="form-group">
<label class="col-lg-12 control-label" for="">Title</label>
<p><%= question.text_field :title %></p>
<%= question.link_to_remove "Remove this answer" %>
</div>
<% end %>
<%= f.link_to_add "Add more questions", :questions %>
<% end %>