2014-06-07 1 views
0

내 form_for 몇 가지 문제가 있어요, 나는이 오류오류 : 형식의 첫 번째 인수는 무기 호를 포함하거나

First argument in form cannot contain nil or be empty

이이이 형태

  <%= 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 

어떻게 수정합니까? 이 index.html.erb에 속하는으로

+0

'form'은 (는) '보기 파일'에 속합니다. – Pavan

+0

블로그보기 폴더 – user3457760

답변

1

, 당신은 index 방법이 라인 @blog = Blog.new을 추가해야합니다.

def index 
@blogs = Blog.all 
@blog = Blog.new 
end 

그리고 또한 update 방법은 wrong.It 미래에 오류가 발생하지 않도록 다음과 같이해야한다.

def update 
    @blog = Blog.update(blog_params) 
    redirect_to root_path 
end 
+0

에있는 index.html.erb에 있습니다. 정말 고맙습니다! – user3457760

관련 문제