Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Polymorphic Associations has_one / belongs_to
    primarykey
    data
    text
    <p>I have the following situation:</p> <p>I have a model called "ConfigurationItem".</p> <pre><code>class ConfigurationItem &lt; ActiveRecord::Base belongs_to :contract_asset belongs_to :provider belongs_to :configuration, polymorphic: true validate :name, :contract_asset, presence: true end </code></pre> <p>Then I have for the moment two models, "OsConfiguration" and "HardwareConfiguration"</p> <pre><code>class OsConfiguration &lt; ActiveRecord::Base has_one :configuration_item, as: :configuration end class HardwareConfiguration &lt; ActiveRecord::Base has_one :configuration_item, as: :configuration end </code></pre> <p>On my process of creation, I first come to the form of ConfigurationItem. So my question is, how can I create an Os or Hardware Configuration from the ConfigurationItem form. Something like this:</p> <p><img src="https://i.stack.imgur.com/t85eD.png" alt="enter image description here"></p> <p>What I tried so far is to route like this:</p> <pre><code>resources :configuration_items do resources :os_configurations resources :hardware_configurations end </code></pre> <p>But the rest is a bit heavy for me (I'm very new to rails).</p> <p>Plus, I'm using this gem : <a href="https://github.com/codez/dry_crud" rel="nofollow noreferrer">https://github.com/codez/dry_crud</a></p> <p>edit:</p> <p>To be more specific, from the configurationItem a form, I can choose an os or hardware configuration. If I choose an os configuration, a modal form will appear with his form. When I save the Os Configuration, I have to set his attribute configuration_item with the previous form, so he's not created yet and I can't access it from the os configuration's controller.</p> <p>It's like in rails_admin when from a form, you can create and add a new instance of an other model.</p> <p>Thank's !</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload