标签: ruby-on-rails-6

Select2 CSS 未通过纱线或资产预编译加载

我遇到了一个奇怪的问题,除了 select2 之外,一切都按预期工作。我有 Rails 6.0.0 应用程序并通过安装 select2 yarn add select2

然后我将其添加到 application.js 文件中。文件如下所示。

    #app/javascripts/packs/application.js

    require("@rails/ujs").start()
    require("turbolinks").start()
    require("@rails/activestorage").start()
    require("channels")
    require('datatables.net')
    require('datatables.net-dt')
    require('datatables.net-bs4')
    require('select2')

    import  "bootstrap"
    import 'popper.js/dist/popper.js';
    import $ from 'jquery';
    global.$ = jQuery;
    import  "chart.js"
    import 'select2'; // globally assign select2 fn to $ element
    import 'select2/dist/css/select2.css';  // optional if you have css loader

    document.addEventListener("turbolinks:load", () => {
        setTimeout(function() {
          $('.success, .alert').fadeOut();
        }, 10000); 
    })

Run Code Online (Sandbox Code Playgroud)

现在看起来像这个 select2 下拉框

当我转到 Chrome 开发人员工具中的“源”选项卡时,它仅显示select2/dist/jsnode_modules 下的文件夹。我已经尝试precompilingclobbering资产但不起作用。整个过程在我的本地运行良好,只会在生产服务器中引起问题。

编辑: …

ruby-on-rails jquery-select2 yarnpkg webpacker ruby-on-rails-6

0
推荐指数
1
解决办法
2585
查看次数

如何使用 ajax 在 Rails 6 应用程序中显示 Bootstrap 4 模式?

目前,我对页面上的每个部分都有一个模态渲染。它有效,但我不想在每次加载页面时为每个部分呈现模式。

这是现在呈现我的模态的代码:

site/gallery.html.erb

<% @pieces.each_slice(3) do |pieces| %>
  <div class="row">
    <% pieces.each do |piece| %>
      <div class="col-lg-4">        
        <%= image_tag (piece.images.joins(:blob).order('active_storage_blobs.filename ASC').first if piece.images.attached?), data: { toggle: "modal", target: "#modal#{piece.id}" }, class:"img-thumbnail mx-auto d-block img-size" %>        
        <p><%= piece.name %></p>
        <p><%= piece.description %></p>
      <%= render 'site/modal', piece: piece %>
      </div>
    <% end %>
  </div>
<% end %>
Run Code Online (Sandbox Code Playgroud)

这是模态部分:

site/_modal.html.erb

<div class="modal fade" id="modal<%=piece.id%>" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalLabel"><%= piece.name %></h5>
        <button type="button" …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails twitter-bootstrap bootstrap-modal bootstrap-4 ruby-on-rails-6

0
推荐指数
1
解决办法
1939
查看次数

如何使用符号查询比较运算符

我目前可以做到这一点

Enrollment.where('starts_at < ?', Time.current)
Run Code Online (Sandbox Code Playgroud)

因为我可以做到这一点

Enrollment.where(starts_at: Time.current)
Run Code Online (Sandbox Code Playgroud)

有没有办法对比较运算符使用相同的格式?我认为其中之一会起作用,但它们不起作用

Enrollment.where(starts_at: "< #{Time.current}")
Run Code Online (Sandbox Code Playgroud)

或者

Enrollment.where('starts_at <': Time.current)
Run Code Online (Sandbox Code Playgroud)

能够做这样的事情真的很棒

Enrollment.where(state: :active, 'starts_at <': Time.current)
Run Code Online (Sandbox Code Playgroud)

postgresql activerecord ruby-on-rails ruby-on-rails-6

0
推荐指数
2
解决办法
76
查看次数

该模型适配器不支持从数据库获取记录

将我的应用程序从 Rails 5.2 升级到 Rails 6 后,我遇到了这个问题

该模型适配器不支持从数据库中获取记录。

class PlayerArtController < ApplicationController
  load_and_authorize_resource only: [:index, :create]

  def index
     
  end

  def create
  end

end
Run Code Online (Sandbox Code Playgroud)

版本:

导轨 (6.0.3.4)
康康康 (2.3.0)
红宝石 2.7.2

ruby-on-rails cancancan ruby-on-rails-6

0
推荐指数
1
解决办法
608
查看次数

为什么我可以在 Rails 6 中的 ActionMailer::MessageDelivery 上使用已删除的“deliver”方法

irb(main)> Rails.version
=> "6.0.3.3"

irb(main)> AwesomeNotifier.send_recommend_notification(self).method(:deliver).owner
AwesomeNotifier#send_recommend_notification: processed outbound mail in 0.2ms
=> ActionMailer::MessageDelivery

irb(main)> AwesomeNotifier::MessageDelivery.instance_methods(false)
=> [:deliver_later!, :deliver_later, :deliver_now!, :deliver_now, :message, :processed?, :__setobj__, :__getobj__]
Run Code Online (Sandbox Code Playgroud)

看起来没有deliver方法,ActionMailer::MessageDelivery 因为它在 5.0提交时
删除了 ,但它以某种方式工作。

这是从哪里来的deliver??
我应该使用deliver_laterordeliver_now但想弄清楚这deliver是什么。

ruby-on-rails actionmailer ruby-on-rails-6

0
推荐指数
1
解决办法
280
查看次数

为什么这个数组元素有数据时会返回nil?

我正在解析 CSV 中的行,这是每个行对象外观的示例:

 pry(Program)> row
=> #<CSV::Row "?Broadcast Name":"2020 FC Cincinnati vs Toronto FC | MLS" "Description":"Major League Soccer is a men's professional soccer league sanctioned by the United States Soccer Federation which represents the sport's highest level in the United States. The league comprises 26 teams—23 in the U.S. and 3 in Canada and constitutes one of the major professional sports leagues in both countries." "Category":"Sports,Soccer" "Sizzle Reel":"https://youtu.be/fM5aHIVBTIc" "Thumbnail Image":"Screen Shot 2020-01-14 at 5.27.31 PM.png (https://dl.airtable.com/.attachments/7d9273fef3fc1cf1a44c4f2c4db395e7/05f3cd4a/ScreenShot2020-01-14at5.27.31PM.png)" "Header Image":"Screen Shot …
Run Code Online (Sandbox Code Playgroud)

ruby csv ruby-on-rails ruby-on-rails-6

-1
推荐指数
1
解决办法
60
查看次数