Add note model in Rails

Posted by dannymcc on Stack Overflow See other posts from Stack Overflow or by dannymcc
Published on 2010-06-01T09:40:17Z Indexed on 2010/06/01 9:43 UTC
Read the original article Hit count: 335

Filed under:
|
|
|

Hi Everyone,

I am following the 15 minute blog tutorial on Ruby on Rails .com: http://media.rubyonrails.org/video/rails_blog_2.mov and am stumbling into some issues.

I am using the following alterations to the names in the tutorial:

posts = kases

comments = notes

I have setup the models as follows:

class Kase < ActiveRecord::Base
  validates_presence_of :jobno
  has_many :notes

  belongs_to :company # foreign key: company_id
  belongs_to :person # foreign key in join table
  belongs_to :surveyor,
             :class_name => "Company",
             :foreign_key => "appointedsurveyor_id"
  belongs_to :surveyorperson,
             :class_name => "Person",
             :foreign_key => "surveyorperson_id"

  def to_param
     jobno
  end

and...

class Note < ActiveRecord::Base
  belongs_to :kase
end

The Notes controller look like this:

  # POST /notes
  # POST /notes.xml
  def create
    @kase = Kase.find(params[:kase_id])
    @note = @kase.notes.build(params[:note])
    redirect_to @kase
  end

and the database scheme for Kases looks like this:

  create_table "notes", :force => true do |t|
    t.integer  "kase_id"
    t.text     "body"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

and for kases...

  create_table "kases", :force => true do |t|
    t.string   "jobno"
    t.date     "dateinstructed"
    t.string   "clientref"
    t.string   "clientcompanyname"
    t.text     "clientcompanyaddress"
    t.string   "clientcompanyfax"
    t.string   "casehandlername"
    t.string   "casehandlertel"
    t.string   "casehandleremail"
    t.text     "casesubject"
    t.string   "transport"
    t.string   "goods"
    t.string   "claimantname"
    t.string   "claimantaddressline1"
    t.string   "claimantaddressline2"
    t.string   "claimantaddressline3"
    t.string   "claimantaddresscity"
    t.string   "claimantaddresspostcode"
    t.string   "claimantcontact"
    t.string   "claimanttel"
    t.string   "claimantmob"
    t.string   "claimantemail"
    t.string   "claimanturl"
    t.string   "lyingatlocationname"
    t.string   "lyingatlocationaddressline1"
    t.string   "lyingatlocationaddressline2"
    t.string   "lyingatlocationaddressline3"
    t.string   "lyingatlocationaddresscity"
    t.string   "lyingatlocationaddresspostcode"
    t.string   "lyingatlocationcontactname"
    t.string   "lyingattel"
    t.string   "lyingatmobile"
    t.string   "lyingatlocationurl"
    t.text     "comments"
    t.string   "invoicenumber"
    t.string   "netamount"
    t.string   "vat"
    t.string   "grossamount"
    t.date     "dateclosed"
    t.date     "datepaid"
    t.datetime "filecreated"
    t.string   "avatar_file_name"
    t.string   "avatar_content_type"
    t.integer  "avatar_file_size"
    t.datetime "avatar_updated_at"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "kase_status"
    t.string   "invoice_date"
    t.integer  "surveyorperson_id"
    t.integer  "appointedsurveyor_id"
    t.integer  "person_id"
    t.string   "company_id"
    t.string   "dischargeamount"
    t.string   "dishchargeheader"
    t.text     "highrisesubject"
  end

Whenever I enter a note into the kase show view's note entry form:

<h2>Notes</h2>
        <div id="sub-notes">
            <%= render :partial => @kase.notes %>
        </div>

        <% form_for [@kase, Note.new] do |f| %>
        <p>
            <%= f.label :body, "New Note" %><br />
            <%= f.text_area :body %>
        </p>
        <p><%= f.submit "Add Note" %></p>
        <% end %>

partial:

<% div_for note do %>
    <p>
        <strong>Created <%= time_ago_in_words(note.created_at) %> ago</strong><br />
        <%= h(note.body) %>
    </p>
<% end %>

I get the following error:

ActiveRecord::RecordNotFound in NotesController#create

Couldn't find Kase with ID=Test Case

I have tried removing the

def to_param
         jobno
      end

from the kase model, but the same error shows.

Any ideas what I'm missing?

Thanks,

Danny

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about model