Jon
Jon

Reputation: 23

using builder in rails

I am creating a form in rails (I have a user that has many answers and answers belong to users).

I have a <%= form_for @user, :remote => true do |f| %> and then embedded a form <%= f.fields_for :answers do |builder| %> which get generated by the controller

if @user.answers.count > 0

else
  1.times { @user.answers.build }        
end

@userposts = User.find(params[:id]).answers`

the problem is I have tried wrapping it in a if statement (not well written I know !) but all I really want is to embed the answers form a certain number of times on the page 5 for example I can change the 1.times to 5 but this will keep generating new forms until they are filled in.

I only want them to generate 5 static questions the first time and then leave them 5 on the page to edit for any further visits.

How can I achieve that?

Upvotes: 1

Views: 116

Answers (1)

Debadatt
Debadatt

Reputation: 6015

If you are using user has many answers, then we can do dynamically answer form

try using gem nested_form(https://github.com/ryanb/nested_form)

Upvotes: 1

Related Questions