【发布时间】:2017-03-17 16:42:03
【问题描述】:
我正在尝试在我的网络应用程序上发布可从浏览器更新的博客文章,但是当我在编辑中单击更新时,我收到此错误: ActiveModel::ForbiddenAttributesError
pots_controller 第 33 行错误:
如果@post.update_attributes(params[:post])
这是我的 edit.html.erb 代码:
<h1>Edit Post</h1>
<%= form_for @post do |f| %>
<p>
<%= f.label :title %><br />
<%= f.text_field :title %><br />
</p>
<p>
<%= f.label :body %><br />
<%= f.text_field :body %><br />
</p>
<p>
<%= f.select :category_id, Category.all.collect {|x| [x.name, x.id]}, {:include_blank => "Select One"} %><br />
</p>
<p>
<%= f.submit "Update post" %>
</p>
<% end %>
<%= link_to "Go Back", post_path %>
这是我的 posts_controller.rb 代码:
class PostsController < ApplicationController
def index
@posts = Post.find(4,5)
end
def show
@post = Post.find(params[:id])
end
def new
@post = Post.new
@category = Category.all
end
def create
@post = Post.new(params[:post])
if @post.save
redirect_to posts_path, :notice => "Your post has been saved"
else
render "new"
end
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
if @post.update_attributes(params[:post])
redirect_to post_path, :notice => "Your post has been updated"
else
render "edit"
end
end
def destroy
@post = Post.find(params[:id])
@post.destroy
redirect_to posts_path, :notice => "Your post has been deleted"
end
end
希望并感谢任何人都可以提供帮助。最好的,M
【问题讨论】:
标签: ruby-on-rails ruby