我正在制作一个博客式应用程序,并且正在编辑时更新帖子。无法在Ruby on Rails上更新帖子
我使用的部分称为_post_form编辑帖子:从我的帖子控制器
<%= form_for(@post) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_area :content, placeholder: "Compose new post..." %>
</div>
<div id="post_button">
<%= f.submit "Post", class: "btn btn-primary" %>
</div>
<% end %>
相关代码:
class PostsController < ApplicationController
before_action :find_note, only: [:show, :edit, :update]
def update
redirect_to @post
end
def find_note
@post = Post.find(params[:id])
end
当我点击“发布”按钮,将我重定向到正确的但是它不会使用我输入到表单中的新文本实际更新它。我觉得我缺少一些基本的东西,但我不确定它是什么。
任何帮助表示赞赏!
感谢这个伟大的答案,我现在明白了很多! – Andrew