Note that there are some explanatory texts on larger screens.

plurals
  1. POruby on rails associations newbie
    text
    copied!<p>This might be considered as a re-post of <a href="https://stackoverflow.com/questions/9245476/rails-3-associations-error/9245684#comment11648767_9245684">rails 3 associations error</a>. But its something which I am not able to understand . But ok ... heres the deal.. I have asked a question in here which was related to a table schema. The post is <a href="https://stackoverflow.com/questions/9213535/what-is-bad-in-this-table-schema-structure/9222079#9222079">what is bad in this table schema structure</a> and the query was :</p> <pre><code>`CREATE TABLE "pages" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "body" varchar(255), "author" varchar(255), "email" varchar(255), "reference" varchar(255), "created_at" datetime, "updated_at" datetime);` </code></pre> <p>I was suggested that I should create separate tables for author, and that is what I tried and messed up. Can anyone please tell me how exactly should the associations work with my scenario? I really need to understand the ROR associations well.</p> <h1>edit-1</h1> <p>Here is my pages migration code:</p> <pre><code>class CreatePages &lt; ActiveRecord::Migration def self.up create_table :pages do |t| t.string :title, :unique =&gt; true, :limit =&gt; 50 t.string :body, :limit =&gt;255 t.string :email, :unique =&gt; true, :limit =&gt; 50 t.string :reference, :limit =&gt; 40 t.timestamps end end def self.down drop_table :pages end end </code></pre> <p>and here is my author migrations:</p> <pre><code>class CreateAuthors &lt; ActiveRecord::Migration def change create_table :authors do |t| t.string :author, :unique =&gt; true, :null =&gt; false, :limit =&gt; 50 t.timestamps end end end </code></pre>
 

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