2013-05-30 70 views
0

這是錯誤,當我在「新帖點擊我越來越:新崗位 - 在形式上第一個參數不能包含零或爲空

形式

第一個參數不能包含零或爲空

我PostController中:

class PostsController < ApplicationController 
before_action :set_user, only: [:show, :edit, :update, :destroy] 

def index 
    @posts = Post.all 
end 

def show 

end 

def edit 

end 

def update 
    @post.update(post_params) 
    redirect_to posts_path 
end 

def new 
    if user_signed_in? 
     @post = Post.new 
    else 
     flash[:alert] = ":(" 
    end 
end 

def create 
    @post = Post.new(post_params) 
    @post.user_id = current_user.id 
    @post.save 
    redirect_to posts_path 
end 

def destroy 
    if user_signed_in? 
     @post.destroy! 
    else 
     flash[:alert] = ":(" 
    end 
    redirect_to posts_path 
end 


private 
def post_params 
    params.require(:post).permit(:body) 
end 

def set_user 
    @post = Post.find(params[:id]) 
end 

和帖子#指數:

<% @posts.each do |post| %> 
<%= post.body %> 
<%= link_to 'Show', post %> 
<%= link_to 'Edit', edit_post_path(post) %> 
<%= link_to 'Delete', post, method: :delete %> 
<br> 


_form.html.erb

<%= form_for(@post) do |f| %> 

    <div class="field"> 
    <%= f.label :body %><br> 
    <%= f.text_area :body %> 
    </div> 
    <div class="actions"> 
    <%= f.submit %> 
    </div> 
<% end %> 

它看起來像你的文章大多是代碼;請添加更多details.It看起來像你的文章主要是代碼;請添加更多details.It看起來像你的文章主要是代碼;請添加更多details.It看起來像你的文章主要是代碼;請添加更多details.It看起來像你的文章主要是代碼;請加一些細節。:(

回答

0

你應該檢查你的「new.html.erb」或「_form.html.erb」文件,看看是否「的form_for」方法正確調用。

+0

錯誤犯規出現時,即時通訊在 – fuskie

+0

登錄請發表你的所有錯誤信息得到。 –

0

如果您使用的設計,您可以通過行動之前加入得到這樣的:

before_action :authenticate_user!, only: [:new] 

和你的新行動:

def new 
    @post = Post.new 
end 
相關問題