ruby - How do I initialize or show a nested form in rails? -


I follow complicated nested forms in Rail Nest and I have done this, there are some changes here and there. But the question is how do I automatically load nested forms without using the controller?

  DEF New @ model = model. New model @ child.build end   

Many thanks!

How do I automatically load the nested form without using the controller? ?

Partial to include a simple (wrong) answer that will define the ActiveRecord object above, such as:

  # app / views / controller / _your_partial .html.erb & lt;% Model = Model New% & gt; & Lt;% mode.child.build% & gt; & Lt;% = Model-do | F | & Gt%;   

Problem With this, it goes against the railways in the world of God,

- -

MVC

Your question is exceptional because it goes against one of the main elements of the rail:

Enter image details here

This means that every request The app (via URL) will be catered by a controller action . The role of the controller is to configure / gather the necessary data to run the app, and then to populate the view for the user.

When you want to call "form without a controller", you are basically saying that you want to go against these conventions unless you make gem (Which will allow you to extrapolate the ActiveRecord definition code outside your controller), you have to use the controller.

-

-

class method

The functionality you use in your controller & amp; Create one to manage it:

  # app / model / model RB class model & lt; ActiveRecord :: Base DF self.build model = self.new model.child.build model end-end   

This will allow you to call the following calls from your Controller / Partial: @model = model. Build # - & gt; Instead of Model.new :)

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -