# Form\_for() question

**URL:** <https://www.ruby-forum.com/t/form-for-question/151167>\
**Category:** Rails\
**Created:** [October 17, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/form-for-question/151167 "2008-10-17T16:32:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zack\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/2bfe46/32.png) [@Zack\_K](https://www.ruby-forum.com/u/Zack_K)\
**Post date:** [October 17, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/form-for-question/151167/1 "2008-10-17T16:32:30Z")

</div>

Well right now i’m currently trying to make a form that posts  
information into my database. I’m using the form\_for function, but  
when i run the server and go to the page and get this error:

undefined method `posts\_path’ for #ActionView::Base:0x23bbabc

So i have no idea what i’m doing wrong, here is the code for the form:

\<% form\_for(@posts) do |p| %\>  
\<%= p.error\_message %\>

\<%= p.label :title %\>  
 \<%= p.text\_field :title %\>

\<%= p.label :post %\>  
 \<%= p.text\_area :post %\>

\<%= p.submit "Submit Post" %\>

\<% end %\>

Any idea?

---

<div class="post-metadata">

**Author:** ![Zack\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/2bfe46/32.png) [@Zack\_K](https://www.ruby-forum.com/u/Zack_K)\
**Post date:** [October 17, 2008, 4:36pm UTC](https://www.ruby-forum.com/t/form-for-question/151167/2 "2008-10-17T16:36:37Z")

</div>

Zack K. wrote:

> Well right now i’m currently trying to make a form that posts  
> information into my database. I’m using the form\_for function, but  
> when i run the server and go to the page and get this error:
> 
> undefined method `posts\_path’ for #ActionView::Base:0x23bbabc

You have no route for posts declared.

---

<div class="post-metadata">

**Author:** ![Zack\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/2bfe46/32.png) [@Zack\_K](https://www.ruby-forum.com/u/Zack_K)\
**Post date:** [October 17, 2008, 4:39pm UTC](https://www.ruby-forum.com/t/form-for-question/151167/3 "2008-10-17T16:39:33Z")

</div>

How do i set the route?  
Sorry, i’m new to Rails

---

<div class="post-metadata">

**Author:** ![Zack\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/2bfe46/32.png) [@Zack\_K](https://www.ruby-forum.com/u/Zack_K)\
**Post date:** [October 17, 2008, 4:56pm UTC](https://www.ruby-forum.com/t/form-for-question/151167/4 "2008-10-17T16:56:34Z")

</div>

Zack K. wrote:

> How do i set the route?  
> Sorry, i’m new to Rails

You can only use named routes (which form\_for uses when you pass it an  
AR object) if you declare them. This is done with the map.resource and  
map.resources methods in your config/routes.rb file. Read up on named  
routes.

---

<div class="post-metadata">

**Author:** ![Zack\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/2bfe46/32.png) [@Zack\_K](https://www.ruby-forum.com/u/Zack_K)\
**Post date:** [October 17, 2008, 6:01pm UTC](https://www.ruby-forum.com/t/form-for-question/151167/5 "2008-10-17T18:01:06Z")

</div>

Well now i have it working so i don’t get an error, but it doesn’t  
submit the information into the server.

---

<div class="post-metadata">

**Author:** ![Zack\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/2bfe46/32.png) [@Zack\_K](https://www.ruby-forum.com/u/Zack_K)\
**Post date:** [October 17, 2008, 6:23pm UTC](https://www.ruby-forum.com/t/form-for-question/151167/6 "2008-10-17T18:23:24Z")

</div>

What do you have in your posts\_controller?
