Couldn't find without an ID

Hello all. I’m new to RoR. I am having trouble trying to get a simple
edit/update going. Everytime I hit submit, I get the following error:
+++++++++++++++++++++
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 called edit.html.erb:

Edit content

<% form_for @content do |f| %>

<%= f.label :title %>
<%= f.text_field :title %>

<%= f.label :verbiage %>
<%= f.text_area :verbiage %>

<%= f.submit “Update”%>
<% end %>
+++++++++++++++++++++++++++++++++++++

Here’s 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.

If you did not use a generator to make your scaffolding, then you may
not have your routes set up correctly. new might be calling edit so
there is not parameter.

On Tue, Feb 23, 2010 at 6:47 AM, Butterson [email protected] wrote:

“authenticity_token”=>“axBSuIWVTMRB2CKcmMO59tqtOlMtXRSXQQ7xeHEMd78=”,
I have a form called edit.html.erb:

@content = Content.new
end

To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.


Curtis C.
[email protected]
home:http://curtiscooley.com
blog:http://ponderingobjectorienteddesign.blogspot.com

Leadership is a potent combination of strategy and character. But if
you must be without one, be without the strategy.
– H. Norman Schwarzkopf

On Feb 23, 8:47 am, Butterson [email protected] wrote:

“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”}}

+++++++++++++++++++++++++++++

Yup, there’s no id param there, and the format value is messed up for
some reason. Even though your code looks fine to me at first glance.

What does your routes.rb file look like?

Jeff

On 23 February 2010 16:09, Jeff [email protected] wrote:

What does your routes.rb file look like?

+1

Thanks for your replies. I didn’t use / or generate scaffolding for
this project. Here is what my routes.rb looks like:

ActionController::Routing::Routes.draw do |map|

map.resource :content
map.resource :weblink
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’
end

After doing a view-source on my form before submission, here’s what I
found:

On 23 February 2010 19:40, Butterson [email protected] wrote:

map.resourceS :content
map.resourceS :weblink

:slight_smile:

On 23 February 2010 14:47, Butterson [email protected] wrote:

The one bit of information you’ve missed out there is the url your
form has posted to. It should be something like:

http://your.site/contents/update/12345

The number at the end of the URL is the id of the “content” record you
are trying to update. If it’s missing something’s wrong somewhere. If
you view source of the html page before you post the form, where does
the form say it’s going to post to?

On 23 February 2010 20:16, Butterson [email protected] wrote:

Uggh! I can’t believe it’s that missing ‘s’ that was causing me
heartache. I also changed ‘content’ to ‘contents’ and it’s working
fine after the update. I guess I need to read more about this
routes.rb file. I still don’t have a 100% grasp on it. Thanks all for
your help.

Pleasure.

http://api.rubyonrails.org/classes/ActionController/Routing.html

Also, you don’t need to wait three days before asking for help. If a
couple of hours of Googling doesn’t solve it, you’re probably about
ready for new eyes on your problem :slight_smile:

Thanks. Well, I work on my project a few hours a day after work so
it’s not exactly 3 straight days. But you’re right, sometimes Googling
just isn’t enough. I’m glad to have found this group. I’m pretty sure
I’ll have a few more questions later. Any other books you can
recommend for Ruby on Rails? I’m starting to love this new framework
after just a few days of experimenting and would like to continue
going deeper. I currently have Simply Rails 2 by Patrick Lenz and
Learning Rails by St. Laurent & Dumbill.

Uggh! I can’t believe it’s that missing ‘s’ that was causing me
heartache. I also changed ‘content’ to ‘contents’ and it’s working
fine after the update. I guess I need to read more about this
routes.rb file. I still don’t have a 100% grasp on it. Thanks all for
your help.

On 23 February 2010 21:31, Butterson [email protected] wrote:

Any other books you can recommend for Ruby on Rails?

“Agile Web D. with Rails” was my first introduction, and it
still proves to be very useful. I was frustrated by “The Rails Way”
(or at least the edition I had) as it was peppered with typos - and
when you’re trying to learn a programming language, errors in the
example code are frustrating.

Another great medium-level book is “Ruby for Rails” (if you can ignore
the cover!). It does skim the basics, but then gets on with the good
stuff.

I can’t recommend highly enough “Refactoring: Ruby Edition” - not
strictly a Rails book, but very good for developing your programming
skills generally, and Ruby specifically.

The best book in my opinion is Agile Web D. with Rails (then
The
Rails Way when you get a bit more advanced).

Cheers,

Andy


Andy J.
http://andyjeffries.co.uk/ #rubyonrails #mysql #jquery
Registered address: 64 Sish Lane, Stevenage, Herts, SG1 3LS
Company number: 5452840

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs