SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard jax502's Avatar
    Join Date
    Jul 2003
    Location
    Jacksonville, FL
    Posts
    1,031
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Couldn't find <Model> without an ID problem

    Hi all,

    I'm new to ruby on rails. i've been following the Simply Rails 2 Book and got me going to creating my own application. I am having trouble trying to get a simple edit/update going. Everytime I hit submit, I get the following error:

    Code:
    Couldn't find Content without an ID
    
    Request
    Parameters:
    {"format"=>"#<content:0x4d3daac>",
     "commit"=>"Update",
     "_method"=>"put",
     "authenticity_token"=>"axBSuIWVTMRB2CKcmMO59tqtOlMtXRSXQQ7xeHEMd78=",
     "content"=>{"title"=>"About Us",
     "verbiage"=>"The company was formed in 2008 by seven healthcare professionals involved in the areas of acute care hospital,
     rehab hospital,
     skilled nursing and rehab,
     out-patient clinics,
     and Home Health Care. Update"}}
    I have a form: edit.html.erb
    Code:
    <h2>Edit content</h2>
    <% form_for @content do |f| %>
    <p>
      <%= f.label :title %><br/>
      <%= f.text_field :title %>
    </p>
    <p>
      <%= f.label :verbiage %><br/>
      <%= f.text_area :verbiage %><br/>
    </p>
    
    <%= f.submit "Update"%>
    <% end %>
    Here is my controller:
    Code:
    class ContentsController < ApplicationController
      layout 'subpages'
      
      def new
        @content = Content.new
      end
      
    
      def create
        @content = Content.new(params[:content])
        @content.save
      end
    
      def edit
        @content = Content.find(params[:id])
      end
      
      def update
          @content = Content.find(params[:id])
          @content.update_attributes(params[:content])
          redirect_to :action => "edit", :id => @content.id
    
      end
    
    end

    i've been trying to figure this out for 3 days but no luck. The solutions on the web and books seem to explain that I need to have id passed to the controller, but I thought form_for @content should already take care of that. I would appreciate all the help i can get. Thanks.
    jax502

  2. #2
    SitePoint Wizard jax502's Avatar
    Join Date
    Jul 2003
    Location
    Jacksonville, FL
    Posts
    1,031
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind...figured it out.
    jax502

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is good etiquette to post your solution even if you found it yourself. That way if others have the same problem and find you post, they can see how you fixed it.

  4. #4
    SitePoint Wizard jax502's Avatar
    Join Date
    Jul 2003
    Location
    Jacksonville, FL
    Posts
    1,031
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the solution:

    I found out that I'm missing an "s" on my routes.rb. Instead of 'map.resources', I had 'map.resource'
    jax502


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •