Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4590008
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:10:46+00:00 2026-05-21T22:10:46+00:00

I have two models, one is for pages and one is for authors. I

  • 0

I have two models, one is for pages and one is for authors.

I have nearly got it to show which author belongs to the pages but keep getting an error, saying:

uninitialized constant Page::Authors

I have defined a method for Authors in my pages controller @pages = @author.pages and not sure if it is right. hear is my code for my controllers.

class PagesController < ApplicationController
  def index
    @pages = Page.find(:all, :order => 'created_at DESC')
  end

  def show
    @page = Page.find(params[:id])
  end

  def new
    @page = Page.new
  end

  def edit
    @page = Page.find(params[:id])
  end

  def create
    @page = Page.new(params[:page])

      if @page.save
          redirect_to(@page, :notice => 'Page was successfully created.')
      else
          render :action => "new"
      end
  end

  def update
    @page = Page.find(params[:id])

      if @page.update_attributes(params[:page])
        redirect_to(@page, :notice => 'Page was successfully updated.')
      else
        render :action => "edit"
      end
  end

  def destroy
    @page = Page.find(params[:id])
    @page.destroy
  end

  def author
   @pages = @author.pages
  end
end

And here is my Authors controller:

class AuthorsController < ApplicationController
  def index
    @authors = Author.find(:all, :order => 'created_at DESC')
  end

  def show
    @author = Author.find(params[:id])
  end

  def new
    @author = Author.new
  end

  def edit
    @author = Author.find(params[:id])
  end

  def create
    @author = Author.new(params[:author])

      if @author.save
        redirect_to(@author, :notice => 'Author was successfully created.') 
      else
        render :action => "new" 
    end
  end

  def update
    @author = Author.find(params[:id])

      if @author.update_attributes(params[:author])
       redirect_to(@author, :notice => 'Author was successfully updated.') 
      else
        render :action => "edit" 
    end
  end

  def destroy
    @author = Author.find(params[:id])
    @author.destroy
  end

  def author_id
    @author = @pages.author
  end
end

I just want to display who has created the pages, I am using a select from the form to get the author which has already been entered into the database. When you create a new page the select list is selected and the content is entered and then when you show the new or show template that is when the error occurs.

In my models I have said belongs_to :author and has_many :pages.

I am close.

Any ideas would be great. thanks

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T22:10:48+00:00Added an answer on May 21, 2026 at 10:10 pm

    What’s missing here is the stack-trace that shows where the line in question is exercised. It is common to make the mistake of referencing the Authors class instead of the actual Author and end up with errors like this. Nothing in what you’ve pasted seems to be problematic in that way.

    If Author has_many :pages and Page belongs_to :author then this should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have two models and one belongs to another. Now normaly you would
I have two models related one-to-many: a Post and a Comment : class Post(models.Model):
I have two models, one a vanilla Django model, another an unmanaged model wrapping
I have two models. one is brand and another is product_detail. brands table has
I have two models, A and B, and one light, L. I would like
If I have two models that are guaranteed to have a one-to-one correspondence, i.e.
I'm trying to get my head around this one: Say you have two models
I have two models e.g. Book and Author . An author can have many
I have two Model/Controllers which are essentially duplicating data (just on different pages). When
I have two models generated with generate scaffolding, one is a LogBook the other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.