ruby on rails - Error: First argument in form cannot contain nil or be empty -
i having issues form_for, keep getting error
first argument in form cannot contain nil or empty
this form
<%= form_for @blog |f| %> <%= f.text_area :blogpost %> <%= f.submit 'add blog'%> <% end %>
this controller
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 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
how fix this?
as belongs index.html.erb
,you should adding line @blog = blog.new
index
method.
def index @blogs = blog.all @blog = blog.new end
and update
method wrong.it should avoid getting error in future.
def update @blog = blog.update(blog_params) redirect_to root_path end
Comments
Post a Comment