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 7983611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:00:44+00:00 2026-06-04T11:00:44+00:00

EDIT3: To wit, DO NOT put migration code in your model.rb files!!! EDIT2: THE

  • 0

EDIT3:
To wit, DO NOT put migration code in your model.rb files!!!

EDIT2: THE QUESTION (?) :
does ANY migration code belong in a model.rb file?

EDIT: Just mentioning extra (system/config/etc) information that I need to share in order to get a good answer to this question from someone (even if it’s not you) would be greatly appreciated. (1-ups for good tips on stack overflow optimization strategies)

First of all, here is the command prompt activity:

C:\Users\davo\Desktop\RailsProjects\simple_cms>rails c
Loading development environment (Rails 3.2.3)
irb(main):001:0> subject = Subject.find(1)
←[1m←[36mSubject Load (1.0ms)←[0m  ←[1mSELECT `subjects`.* FROM `subjects` WHERE       `subjects`.`id` = 1
LIMIT 1←[0m
=> #<Subject id: 1, name: "Initial Subject", position: 1, visible: true, created_at:"2012-05-18 01:00:26", updated_at: "2012-05-18 01:11:21">
irb(main):002:0> subject.pages
(Object doesn't support #inspect)

The basic schema is that we have two models here, page.rb and subject.rb. Subject is the parent of Page, as you will see. Here are the two models.

Guide to viewing this code: I think all that is relevant to this problem in these two models are the has_many and belongs_to tags. And I admit, I feel like there should be some foreign keys here. Should there be foreign keys here? Or is that wrong too?

subject.rb

class Subject < ActiveRecord::Base
  # attr_accessible :title, :body
  has_many :pages

  scope :visible, where(:visible => true)
  scope :invisible, where(:visible => false)
  scope :search, lambda {|query| where(["name LIKE ?", "%#{query}%"])}
end

page.rb

class Page < ActiveRecord::Base
  has_many :sections
  belongs_to :subject
  # attr_accessible :title, :body
  create_table "Pages" do |t|
  t.string "name"
  t.string "permalink"
  t.integer "position"
  t.boolean "visible?"

  end
end

I’m really new at this, so please forgive me if I didn’t give you some piece of information that you need. Please let let know what extra information you need, I’m not sure where the error is coming from but I know this is a model (M….VC) issue. 95% on that one.

  • 1 1 Answer
  • 0 Views
  • 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-06-04T11:00:47+00:00Added an answer on June 4, 2026 at 11:00 am

    You have a migration in your model.

    create_table "Pages" do |t|
      t.string "name"
      t.string "permalink"
      t.integer "position"
      t.boolean "visible?"
    end
    

    Should be in ./db/migrate/{timestamp}_create_pages.rb. This file was generated for you if you did rails g model page

    You also need a subject_id column to store the relation to subject

    class CreatePages < ActiveRecord::Migration
      def change
        create_table :pages do |t|
          t.integer :subject_id
          t.string :name
          t.string :permalink
          t.integer :position
          t.boolean :visible?
    
          t.timestamps
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: Do not edit the layout of this code! (See answer below for the
edit3: i added the webconfig from the server edit2: I ran the log and
edit3: i am using this script inside a facebook app, and not sure how
This question has been asked more than once before, but I have not found
EDIT: Duplicate of Should Entity Framework Context be Put into Using Statement? I've been
EDIT: There's now a doc page on this so this question is irrelevant, also
I am at wit's end. I have a working install of python 2.6.5 with
how do i add code to an existing function, either before or after? for
Imagine that I have a C# application that edits text files. The technique employed
I can’t made my .NET 2.0 applications (and services) to load their appname.exe.config files

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.