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"=>"1@live.com"}, "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
我是否必须手动将@invite.new
与require(:story)
相关联,如果是,我该怎么做?
答案 0 :(得分:1)
我错误地使用了require
属性。
假设是params.require(:invite ).permit(:title, :story, :body, :id, :user_id)
。
课程invite
需要invite
,与外部故事相反。