Using the perennial example of a Blog webapp (and all resources are currently automatically mapped in routes.rb):
I have a simple index page that lists all my Post titles. I would like to add a form at the bottom of this page to quickly create n开发者_如何学Pythonew Posts.
I'm new to Rails and can't seem to figure this out! Please help!
Try something like:
<% form_for Post.new do |form| %>
(Insert fields here:)
<%= form.label :fieldname %>
<%= form.text_field :fieldname %>
<%= form.submit "Create" %>
<% end %>
Add this to app/views/posts/index.html.erb
.
Yes you have both index and create actions in the index view.
display list in a index.html.erb then form to create a new post.
after creating new post redirect to index action only.
精彩评论