Reputation: 25
I cant get the syntax of this correct I'm trying to include :url => posts_path in the form_for section
<% form_for :post do |f| %>
<p>
<%= f.label :text %><br>
<%= f.text_area :text %></p>
<p><%= f.submit %></p>
<% end %>
Upvotes: 1
Views: 52
Reputation: 4169
There are a few ways to do this. Like @meager, you want to call Post.new
. I usually do it in the controller, though.
posts_controller.rb
@post = Post.new
view
<% form_for @post do |f| %>
...
<% end %>
You can use a custom path if that's where you want to send the data. So if you have a special case, you can make a route for it
routes.rb
get '/special', to: 'posts#special'
then you can have a form that says...
<% form_tag special_path do |f| %>
...
<% end %>
and the params will pass as you'd think. Notice the form_tag
instead of form_for
though.
Upvotes: 0
Reputation: 239291
form_for
expects an instance of a model, not a symbol:
<% form_for Post.new do |f| %>
...
<% end %>
Upvotes: 2