Forum: Ruby on Rails Couldn't find without an ID

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
60bb25c88eda9e783e1d22653e26f86d?d=identicon&s=25 Smarty 2k (smartee)
on 2008-11-20 10:58
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
648a71a35ce6e4a1c5cd63451a2a20df?d=identicon&s=25 Gavin Morrice (dr_gavin)
on 2008-11-20 11:22
(Received via mailing list)
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

On Nov 20, 9:58 am, Smarty 2k <rails-mailing-l...@andreas-s.net>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-20 11:24
(Received via mailing list)
On 20 Nov 2008, at 09:58, Smarty 2k wrote:

>
> def form_for_test
>  @blog= Blog.find[:all]
>

that's wrong. You probably meant Blog.find :all or Blog.find(:all)
(which are the same)

Fred
648a71a35ce6e4a1c5cd63451a2a20df?d=identicon&s=25 Gavin Morrice (dr_gavin)
on 2008-11-20 11:59
(Received via mailing list)
Well spotted Fred!
wouldn't this be even easier though:
@blog = Blog.all

Gavin

On Nov 20, 10:23 am, Frederick Cheung <frederick.che...@gmail.com>
648a71a35ce6e4a1c5cd63451a2a20df?d=identicon&s=25 Gavin Morrice (dr_gavin)
on 2008-11-20 12:03
(Received via mailing list)
Well spotted Fred!
wouldn't this be even easier though:
@blog = Blog.all

Gavin

On Nov 20, 10:23 am, Frederick Cheung <frederick.che...@gmail.com>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-20 12:25
(Received via mailing list)
On 20 Nov 2008, at 11:03, Dr_Gavin wrote:

>
>
> Well spotted Fred!
> wouldn't this be even easier though:
> @blog = Blog.all

if you're on 2.1 or higher then yes
This topic is locked and can not be replied to.