# Couldn't find without an ID

**URL:** <https://www.ruby-forum.com/t/couldnt-find-without-an-id/153706>\
**Category:** Rails\
**Created:** [November 20, 2008, 10:58am UTC](https://www.ruby-forum.com/t/couldnt-find-without-an-id/153706 "2008-11-20T10:58:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![smartee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e5b9ba/32.png) [@smartee](https://www.ruby-forum.com/u/smartee)\
**Post date:** [November 20, 2008, 10:58am UTC](https://www.ruby-forum.com/t/couldnt-find-without-an-id/153706/1 "2008-11-20T10:58:39Z")

</div>

hi friends…  
my rhtml is for\_for\_test.rhtml

 Form\_For Tester \<% form\_for :blog, :url =\> { :action =\> 'save', :id =\> @blog } do |f| %\> Name: \<%= f.text\_field :blog %\> \<%= submit\_tag 'Save' %\> \<% end %\> 

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

---

<div class="post-metadata">

**Author:** ![smartee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e5b9ba/32.png) [@smartee](https://www.ruby-forum.com/u/smartee)\
**Post date:** [November 20, 2008, 11:24am UTC](https://www.ruby-forum.com/t/couldnt-find-without-an-id/153706/2 "2008-11-20T11:24:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![smartee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e5b9ba/32.png) [@smartee](https://www.ruby-forum.com/u/smartee)\
**Post date:** [November 20, 2008, 11:59am UTC](https://www.ruby-forum.com/t/couldnt-find-without-an-id/153706/3 "2008-11-20T11:59:17Z")

</div>

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

Gavin

On Nov 20, 10:23 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![smartee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e5b9ba/32.png) [@smartee](https://www.ruby-forum.com/u/smartee)\
**Post date:** [November 20, 2008, 12:03pm UTC](https://www.ruby-forum.com/t/couldnt-find-without-an-id/153706/4 "2008-11-20T12:03:59Z")

</div>

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

Gavin

On Nov 20, 10:23 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![smartee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e5b9ba/32.png) [@smartee](https://www.ruby-forum.com/u/smartee)\
**Post date:** [November 20, 2008, 12:25pm UTC](https://www.ruby-forum.com/t/couldnt-find-without-an-id/153706/5 "2008-11-20T12:25:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![smartee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e5b9ba/32.png) [@smartee](https://www.ruby-forum.com/u/smartee)\
**Post date:** [November 20, 2008, 11:22am UTC](https://www.ruby-forum.com/t/couldnt-find-without-an-id/153706/6 "2008-11-20T11:22:20Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
