11175
(-- --)
November 20, 2008, 9:58am
1
hi friends...
my rhtml is for_for_test.rhtml
<html>
<head>
<title>Form_For Tester</title>
</head>
<body>
<% form_for :blog, :url => { :action => 'save', :id => @blog } do
f> %>
Name: <%= f.text_field :blog %>
<%= submit_tag 'Save' %>
<% end %>
</body>
</html>
controller is
def form_for_test
@blog= Blog.find[:all]
end
def save
blog = Blog.find(params[:id])
blog.update_attributes(params[:blog])
redirect_to :action => 'form_for_test'
end
error msg: Couldn't find Blog without an ID
Dr_Gavin
(Dr_Gavin)
November 20, 2008, 10:21am
2
Hi! just briefly glancing over this but try adding '.id' to the :id =>
on your form_for tag
So: <% form_for :blog, :url => { :action => 'save', :id => @blog.id }
do |f| %>
Gavin
that's wrong. You probably meant Blog.find :all or Blog.find(:all) (which are the same)
Fred
Dr_Gavin
(Dr_Gavin)
November 20, 2008, 10:58am
4
Well spotted Fred!
wouldn't this be even easier though:
@blog = Blog.all
Gavin
Dr_Gavin
(Dr_Gavin)
November 20, 2008, 11:03am
5
Well spotted Fred!
wouldn't this be even easier though:
@blog = Blog.all
Gavin
Well spotted Fred!
wouldn't this be even easier though:
@blog = Blog.all
if you're on 2.1 or higher then yes