开发者

Can I have both index and create actions in the index view?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜