2014-11-23 53 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

相关问题