Closed Halvanhelv closed 3 years ago
Not entirely sure why you ask this, as afaik this is easily to test and confirm. So
@questions.links.build
in the controller new
actionBut I am not sure I understood you correctly. If you show me some code, or explain your actual case in more detail (is the link
required? If you can have only one link, why use a has_many
(you wrote the plural form). If they can have more, how will the users add extra links (dynamically in one form --use cocoon). But there are many ways to add nested items to a parent, cocoon is only one of them.
Not entirely sure why you ask this, as afaik this is easily to test and confirm. So
- if you want to show a form with one (empty) link, do something like
@questions.links.build
in the controllernew
action- if you do not need to add more links dynamically, you do not need cocoon
But I am not sure I understood you correctly. If you show me some code, or explain your actual case in more detail (is the
link
required? If you can have only one link, why use ahas_many
(you wrote the plural form). If they can have more, how will the users add extra links (dynamically in one form --use cocoon). But there are many ways to add nested items to a parent, cocoon is only one of them.
Sorry for my bad English, I mean without cocoon I need to create an object to display any form, but does cocoon work without creating an object in "action"?
If I didn't write @ questions.links.build in "new" I can't see the form, later I added cocoon and the form works without @ questions.links.build, does the cocoon require @ questions.links.build to work correctly?
It seems obvious to me, but: no, cocoon does not require the pre-building of the nested items, as users of your website can dynamically add them using the link_to_add_association
link. This greatly depends on the wanted user experience: a lot of sites prefer to already show one empty nested item (if users will add at least one anyone --one click less), but technically there is no need.
Of course, if you seem to have the experience your website does not work without the @question.links.build
there is a very common error where the link_to_add_association
is rendered inside the nested child partial (due to not entirely comprehending how haml works). For clarity one could always check the ERB example code here.
It seems obvious to me, but: no, cocoon does not require the pre-building of the nested items, as users of your website can dynamically add them using the
link_to_add_association
link. This greatly depends on the wanted user experience: a lot of sites prefer to already show one empty nested item (if users will add at least one anyone --one click less), but technically there is no need.Of course, if you seem to have the experience your website does not work without the
@question.links.build
there is a very common error where thelink_to_add_association
is rendered inside the nested child partial (due to not entirely comprehending how haml works). For clarity one could always check the ERB example code here.
thanks for the answer
Hi, do I need to create an association in the controller like questions.links.new to display the form, without using a library it is required to show the form and for cocoon do I need to do this?