Forum: Ruby on Rails form_for() question

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.
Zack K. (Guest)
on 2008-10-17 18:32
(Received via mailing list)
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>
    <%= p.label :title %><br />
    <%= p.text_field :title %>
  </p>
  <p>
    <%= p.label :post %><br />
    <%= p.text_area :post %>
  </p>
  <p>
    <%= p.submit "Submit Post" %>
  </p>
<% end %>

Any idea?
Andrew P. (Guest)
on 2008-10-17 18:36
(Received via mailing list)
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.
Zack K. (Guest)
on 2008-10-17 18:39
(Received via mailing list)
How do i set the route?
Sorry, i'm new to Rails
Andrew P. (Guest)
on 2008-10-17 18:56
(Received via mailing list)
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.
Zack K. (Guest)
on 2008-10-17 20:01
(Received via mailing list)
Well now i have it working so i don't get an error, but it doesn't
submit the information into the server.
infinteVerve (Guest)
on 2008-10-17 20:23
(Received via mailing list)
What do you have in your posts_controller?
This topic is locked and can not be replied to.