Can I have an index and create actions on the index view?

Using a multi-year Blogger web app example (and all resources are currently automatically mapped to route.rb):

I have a simple index page that lists all of my titles. I would like to add a form at the bottom of this page to quickly create new posts.

I'm new to Rails and can't figure it out! Please, help!

+2


a source to share


2 answers


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

.

+1


a source


Yes, you have an index and create actions in the index view.

display the list in the index.html.erb file, then create a new post.



after creating a new post redirect for the index action only.

0


a source







All Articles