2017-05-06 94 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,因爲反對外部故事。

相關問題