- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我用过 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/
我正在使用 Liip functional test bundle 在 Symfony 中创建一个功能测试. 我目前无法提交表单。 我正在尝试使用功能测试添加一个新的“日志”。 如果我尝试通过 UI
当我尝试登录时,请求被 Security 组件屏蔽。我怎样才能让它正常工作? 我有一个简单的登录表单 Form->create('User', array('acti
编辑: 提出这个问题后获得的一系列新见解告诉我问题是什么,它绝对与描述的服务器迁移没有任何关系。 给出的两个答案显示了如何为 CakePHP 2 和 3“修复”这个问题,但请记住这可能会带来安全风险。
我在 laravel 4.1 中做简单的 cms,我创建了许多表单并且它们工作正常,但我创建的最后一个表单在提交时抛出错误。 Illuminate \ Database \ Eloquent \ Ma
我有一个应用程序,客户端用 HTML 和 Angularjs 编写,服务器端用 Laravel 5 编写。每次提交表单时,我都会使用 $http 将模型发送到我的 laravel 5 应用程序,但我一
我不明白为什么 AJAX 请求 (XSRF-TOKEN) 的 token 与 _token 不同正常形式使用。此外,它更长。为什么?为什么有 2 个 token 呢?为什么不使用一个对 ajax 和普
我尝试更新我的表类别的记录,但它显示错误 Column not found: 1054 Unknown column '_token' 路线 Route::post('/categorias/edit
我是一名优秀的程序员,十分优秀!