2017-05-06 59 views
0
param is missing or the value is empty: story 

我得到这个奇怪的错误,我所需要的参数是丢失:参数是丢失或为空值:故事轨

class InvitesController < ApplicationController 
    def index 
    @invite = Invite.new 
    end 

    def create 
    @invite = Invite.new(invite_params) 
    @invite.sender_id = current_user.id 
end 

def invite_params 
    params.require(:story).permit(:title, :story, :body, :id, :user_id) 
end 

在错误的屏幕,参数明确指出story => "3"

{"utf8"=>"✓", "authenticity_token"=>"WDwu3UR/ZtAMKFVwJP4bb83BvdG+RBndP1wKBYT4t7V4BX2N/j/0Tl7VlJnHjObS7ahh2Qjw5oSwuKGyrUgWQw==", "invite"=>{"story"=>"3", "email"=>"[email protected]"}, "commit"=>"Send"} 


class Invite < ApplicationRecord 
    belongs_to :story 
    belongs_to :sender, :class_name => 'User' 
    belongs_to :recipient, :class_name => 'User' 
end 

create_table "invites", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t| 
    t.string "email" 
    t.integer "story_id" 
    t.integer "sender_id" 
    t.integer "recipient_id" 
    t.string "token" 
    t.boolean "accept" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    t.index ["story_id"], name: "index_invites_on_story_id", using: :btree 
end 

难道我有个手动链接​​如果是这样,我该怎么做?

回答

0

我错误地使用了require属性。

它假设为params.require(:invite).permit(:title, :story, :body, :id, :user_id)

该类invite要求invite,因为反对外部故事。

相关问题