小编ant*_*tin的帖子

Vue.js 自定义指令:$refs 为空

背景

\n\n

我按照本指南创建了一个自定义指令(以检测元素外部的点击):https: //tahazsh.com/detect-outside-click-in-vue

\n\n

元素:

\n\n
<button\n id=\'burger\'\n ref=\'burger\'\n class=\'burger button is-white\'>\n <span class=\'burger-top\' aria-hidden=\'true\' style=\'pointer-events: none;\'></span>\n\n <span class=\'burger-bottom\' aria-hidden=\'true\' style=\'pointer-events: none;\'></span>\n</button>\n
Run Code Online (Sandbox Code Playgroud)\n\n

指示:

\n\n
import Vue from \'vue\';\n\nlet handleOutsideClick;\n\nVue.directive(\'outside\', {\n  bind(el, binding, vnode) {\n    setTimeout(() => {\n      handleOutsideClick = (e) => {\n        e.stopPropagation();\n\n        const { handler, exclude } = binding.value;\n\n        let clickedOnExcludedEl = false;\n\n        exclude.forEach((refName) => {\n          if (!clickedOnExcludedEl) {\n            const excludedEl = vnode.context.$refs[refName]\n            console.log(vnode.context.$refs);\n            clickedOnExcludedEl = excludedEl.contains(e.target);\n          }\n        });\n\n        if (!el.contains(e.target) && !clickedOnExcludedEl) {\n          vnode.context[handler]();\n        }\n …
Run Code Online (Sandbox Code Playgroud)

vue.js vuejs2 vue-directives

7
推荐指数
1
解决办法
2256
查看次数

Ruby on Rails:发现不允许的参数:_method、authenticity_token

我使用本指南作为从头开始创建消息传递系统的起点。

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

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

我遇到错误:

found unpermitted parameters: _method, authenticity_token
Run Code Online (Sandbox Code Playgroud)

这里是参数:

{"_method"=>"post", "authenticity_token"=>"BL2XeA6BSjYliU2/rbdZiSnOj1N5/VMRhRIgN8LEXYPyWfxyiBM1SjYPofq7qO4+aqMhgojvnYyDyeLTcerrSQ==", "recipient_id"=>"1", "sender_id"=>"30", "controller"=>"conversations", "action"=>"create"}
Run Code Online (Sandbox Code Playgroud)

我被定向到params.permit我的控制器中的行:

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], …
Run Code Online (Sandbox Code Playgroud)

parameters ruby-on-rails

5
推荐指数
1
解决办法
4883
查看次数

Rails查询:根据最新的子记录获取所有父记录

订单has_manyorder_events。

Anorder_event是订单状态的记录,例如pending_approvalconfirmed等。

通过创建 来跟踪订单的更改order_events

我通常通过执行以下操作来获取订单的当前状态:order.order_events.last.try(:state)

我想要一个查询来获取具有给定当前状态的所有订单,例如当前状态为 的所有订单cancelable

我最初在模型中有一个范围OrderEvent

scope :cancelable, -> { where('state = ? OR state = ?', 'pending_approval', 'pending_confirmation') }
Run Code Online (Sandbox Code Playgroud)

然后是模型中的范围Order

scope :with_dates_and_current_state_cancelable, -> { with_dates.joins(:order_events).merge(OrderEvent.cancelable) }
Run Code Online (Sandbox Code Playgroud)

并只是将后者用于其他目的。

这里的问题是它返回当前或过去满足条件的所有订单。

获取当前满足条件的所有订单的最佳方式是什么?

activerecord ruby-on-rails

2
推荐指数
1
解决办法
2182
查看次数