Rails Error "uninitialized constant User::Corporateprofiles"
<p>Im trying to make a program in which when a user is created, automatically a corporateprofile is automatically created along with it. However upon trying to view the corporate profile i keep running into the below error..</p>

<p>NameError in CorporateprofilesController#show</p>

<pre><code>uninitialized constant User::Corporateprofiles
</code></pre>

<p>I have read through my code over and over for spelling mistakes however no avail, also please note I am using nested routes in which each user has on corporateprofile.</p>

<p>Routes.rb</p>

<pre><code>Myapp::Application.routes.draw do
  resources :users do
    resources :searches
    resources :corporateprofiles
  end
end
</code></pre>

<p>Corporateprofiles Controller</p>

<pre><code>class CorporateprofilesController &lt; ApplicationController
  before_action :require_user

  def show
    @corporateprofile = current_user.corporateprofiles.find(params[:id])
  end

  def edit
    @corporateprofile = current_user.corporateprofiles.find(params[:id])
  end

  def update
    @corporateprofile = Corporateprofile.find(current_user.corporateprofile.id)
    if @corporateprofile.update_attributes(corporateprofile_params)
      flash[:success] = "Profile Updated"
      redirect_to current_user
    else
      flash.now[:error] = "Something went wrong" 
      render edit_user_corporateprofiles_path
    end
  end

  private

  def profile_params
    params.require(:corporateprofile).permit(:companyname, :companylogo,:companybanner,:companywebsite,:companyindustry,:companytype, :companyheadquarters,:companysize,:companyvideo,:aboutus,:city,:state,:country)
  end
end
</code></pre>

<p>Corporate Profile Model</p>

<pre><code>class Corporateprofile &lt; ActiveRecord::Base
 belongs_to :user
end
</code></pre>

<p>User Model</p>

<pre><code>class User &lt; ActiveRecord::Base
  after_create :build_profile

  has_many :searches, dependent: :destroy
  has_one :corporateprofiles, dependent: :destroy

  def build_profile
    Corporateprofile.create(user: self) # Associations must be defined correctly for this syntax, avoids using ID's directly.
  end

  has_secure_password 
end
</code></pre>

<p>Have read all the similar stack overflow posts even the error checking ones however I'm still unable to figure out whats causing the error.</p>

<p>Any help would be so much appreciated</p>