gpt4 book ai didi

ruby-on-rails - Ruby on Rails : found unpermitted parameters: _method, 真实性_token

转载 作者:行者123 更新时间:2023-12-04 03:52:11 24 4
gpt4 key购买 nike

我用过 this guide作为从头开始创建消息传递系统的起点。

一切正常。但出于某种原因,每当我现在尝试通过在我的 View 中单击以下链接来创建新对话时

<%= link_to 'Message me', conversations_path(sender_id: current_user.id, recipient_id: @user.id), class: 'btn btn-primary', method: :post %>

我遇到错误:
found unpermitted parameters: _method, authenticity_token

这里是参数:
{"_method"=>"post", "authenticity_token"=>"BL2XeA6BSjYliU2/rbdZiSnOj1N5/VMRhRIgN8LEXYPyWfxyiBM1SjYPofq7qO4+aqMhgojvnYyDyeLTcerrSQ==", "recipient_id"=>"1", "sender_id"=>"30", "controller"=>"conversations", "action"=>"create"}

我被定向到 params.permit我的 Controller 中的行:
class ConversationsController < ApplicationController
before_action :authenticate_user!

# GET /conversations
# GET /conversations.json
def index
@users = User.all

# Restrict to conversations with at least one message and sort by last updated
@conversations = Conversation.joins(:messages).uniq.order('updated_at DESC')
end

# POST /conversations
# POST /conversations.json
def create
if Conversation.between(params[:sender_id], params[:recipient_id]).present?
@conversation = Conversation.between(params[:sender_id], params[:recipient_id]).first
else
@conversation = Conversation.create!(conversation_params)
end

redirect_to conversation_messages_path(@conversation)
end

private
# Use callbacks to share common setup or constraints between actions.
def conversation_params
params.permit(:sender_id, :recipient_id)
end
end

奇怪的是,我之前没有这个问题,我也没有做任何改变。可能是什么问题?

最佳答案

您的参数可能应该像这样定义:

def conversation_params
params.require(:conversation).permit(:sender_id, :recipient_id)
end

这应该确保表单自动生成的其他隐藏参数不会被阻止。

关于ruby-on-rails - Ruby on Rails : found unpermitted parameters: _method, 真实性_token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33089902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com