title: Ruby on rails and composition in OOP: How can I access attributes in simple_form?
body: <p>I am making a form for sign up and I have a class named ManagedCompany, that have an attribute named company of the class Company. The class Company have an attribute from another class named Address. So, there are compositions in those classes.</p>
  
  <p>The classes are presented below:</p>
  
  <p><strong>app/models/managed_company.rb</strong></p>
  
  <pre><code>class ManagedCompany
    include ActiveModel::Model
  
    def initialize
      @company = Company.new
    end
  
    attr_accessor :name, :string
    attr_accessor :company, :Company
  
  end
  </code></pre>
  
  <p><strong>app/models/company.rb</strong></p>
  
  <pre><code>class Company
    include ActiveModel::Model
  
    def initialize
      @address = Address.new
    end
  
    attr_accessor :category, :string
    attr_accessor :name, :string
    attr_accessor :address, :Address
  
    validates_presence_of :category
    validates_presence_of :name
  
  end
  </code></pre>
  
  <p><strong>app/models/address.rb</strong></p>
  
  <pre><code>class Address
    include ActiveModel::Model
  
    attr_accessor :street, :string
    attr_accessor :number, :string
  
    validates_presence_of :street
    validates_presence_of :number
  
  end
  </code></pre>
  
  <p>My form:</p>
  
  <pre><code>&lt;%= simple_form_for @managed_company do |form| %&gt;
  
    &lt;%= form.input :company.address.street, autofocus: true %&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>But this way did not work. The error message: </p>
  
  <pre><code>undefined method `address' for :company:Symbol
  </code></pre>
  
  <p>So, in the form (simple_form of ruby on rails), how can I access the attribute street from the address object?</p>
  
  <p><strong>Edit: add controllers code</strong></p>
  
  <p><strong>app/controllers/managed_companies_controller.rb</strong></p>
  
  <pre><code>class ManagedCompaniesController &lt; ApplicationController
  
    def new
      @managed_companies = ManagedCompanies.new
    end
  
    def create
      @managed_companies = ManagedCompanies.new(secure_params)
      if @managed_companies.valid?
  
      else
        render :new
      end
    end
  
    private
  
    def secure_params
      params.require(:managed_companies).permit(:name)
    end
  
  end
  </code></pre>
  
  <p><strong>app/controllers/companies_controller.rb</strong></p>
  
  <pre><code>class CompaniesController &lt; ApplicationController
  
    def new
      @company = Company.new
    end
  
    def create
      @company = Company.new(secure_params)
      if @company.valid?
  
      else
        render :new
      end
    end
  
    private
  
    def secure_params
      params.require(:company).permit(:name)
    end
  
  end
  </code></pre>
  
  <p><strong>app/controllers/addresses_controller.rb</strong></p>
  
  <pre><code>class AddressesController &lt; ApplicationController
  
    def new
      @address = Address.new
    end
  
    def create
      @address = Address.new(secure_params)
      if @address.valid?
  
      else
        render :new
      end
    end
  
    private
  
    def secure_params
      params.require(:address).permit(:street)
    end
  
  end
  </code></pre>