2014-11-23 64 views
0

我使用的設計和導軌4.我有以下型號:新使用Rails 4 - ::加載ActiveModel ForbiddenAttributesError

class Video 
    include Mongoid::Document 
    include Mongoid::Timestamps 

    field :url,    type: String 
    field :video_id,   type: String 
    field :title,    type: String 
    field :description,  type: String 
    field :suggested_by_name, type: String 
    field :suggested_by_email, type: String 
    field :active,    type: Boolean, default: false 

end 

與以下控制器:

class Frontend::VideosController < ApplicationController 

    before_action :authenticate_user!, only: [:index, :edit, :update, :destroy] 

    def index 
    end 

    def new 
    @videos = Video.new 
    end 

    def create 
    if @person = Video.create(params[:video]) 
     flash.now[:success] = "Thanks for suggest this video" 
     redirect_to root_path 
    else 
     flash.now[:error] = "Impossible to add this suggestion" 
     redirect_to new_frontend_video_path 
    end 
    end 

    def edit 
    end 

    def update 
    end 

    def destroy 
    end 

    private 
    def video_params 
     params.require(:video).permit(:url, :title, :description, :suggested_by_name, :suggested_by_email) 
    end 

end 

我想保存記錄在我的MongoDB,但我得到:

::加載ActiveModel ForbiddenAttributesError

所以我認爲我犯了一個強參數的錯誤,有些幫助請。

回答

0

create動作變化params[:video]video_params

def create 
    if @person = Video.create(video_params) 
     flash.now[:success] = "Thanks for suggest this video" 
     redirect_to root_path 
    else 
     flash.now[:error] = "Impossible to add this suggestion" 
     redirect_to new_frontend_video_path 
    end 
    end 

你應該permit參數,可以代替Rails提高ActiveModel::ForbiddenAttributesError

相關問題