【发布时间】:2014-06-07 16:17:56
【问题描述】:
我的 form_for 有一些问题,我不断收到此错误
表单中的第一个参数不能包含 nil 或为空
这是表格
<%= form_for @blog do |f| %>
<%= f.text_area :blogpost %>
<%= f.submit 'Add Blog'%>
<% end %>
这是我的控制器
class BlogsController < ApplicationController
def index
@blogs = Blog.all #.paginate(page: params[:page], per_page: 5)
end
def create
@blog = Blog.create(blog_params)
redirect_to root_path, notice: "Created a Blog"
end
def update
@blog = Blog.create(blog_params)
redirect_to root_path
end
def show
@blog = Blog.find(params[:id])
end
def new
@blog = Blog.new
end
def edit
@blog = Blog.find(params[:id])
end
def destroy
@blog = Blog.find(params[:id])
@blog.destroy
redirect_to root_path
end
private
def blog_params
params.require(:blog).permit(:blogpost)
end
end
我该如何解决这个问题?
【问题讨论】:
-
你的
form属于哪个view file? -
我在博客视图文件夹中的 index.html.erb 中有它
标签: ruby-on-rails forms ruby-on-rails-4 controller