由于多种原因,我将上传内容从 ActiveStorage (AS) 迁移到 CarrierWave (CW)。
我正在制作 rake 任务并整理逻辑 - 我对如何将 AS blob 馈送到 CW 文件感到困惑。
我正在尝试类似的事情:
@files.each.with_index(1) do | a, index |
if a.attachment.attached?
a.attachment.download do |file|
a.file = file
end
a.save!
end
end
Run Code Online (Sandbox Code Playgroud)
这是基于这两个链接:
https://edgeguides.rubyonrails.org/active_storage_overview.html#downloading-files
message.video.open do |file|
system '/path/to/virus/scanner', file.path
# ...
end
Run Code Online (Sandbox Code Playgroud)
和
https://github.com/rierwaveuploader/rierwave#activerecord
# like this
File.open('somewhere') do |f|
u.avatar = f
end
Run Code Online (Sandbox Code Playgroud)
我在本地测试了这个,文件不是通过上传器安装的。我的问题是:
奖金业力问题:
我有一个现有的Rails应用程序,用于Devise验证User模型并Pundit根据Enrollment链接User到我的Company模型的模型进行身份验证.双方User并Company都在公寓宝石的公共架构.我不怀疑公寓是问题的一部分,但我想我会提到它.
我使用AdminUser类添加了Active Admin - 我希望将我的管理员用户与应用用户分开.
如果我尝试访问/admin或/admin/dashboard获得:
Pundit::PolicyScopingNotPerformedError at /admin/users
Pundit::PolicyScopingNotPerformedError
Run Code Online (Sandbox Code Playgroud)
如果我尝试像/admin/usersPundit 这样的模型似乎忽略了active_admin策略并转到主应用程序策略.在我的情况下,应用程序会抛出异常,因为它是在等一个EnrollmentVS的AdminUser.
如果我禁用:
##/config/initializers/active_admin.rb
config.authorization_adapter = ActiveAdmin::PunditAdapter
##/controllers/application_controller
after_action :verify_authorized, except: [:landing, :dashboard], unless: :devise_controller?
after_action :verify_policy_scoped, only: [:index]
Run Code Online (Sandbox Code Playgroud)
一切正常,但后来我在主应用程序中失去了Pundit等.
这是我的代码的要点:
https://gist.github.com/jasper502/4b2f1b8b6f21a26c64a5
以下是可以在此问题上找到的相关帖子:
https://gorails.com/forum/using-pundit-with-activeadmin
我想在这篇文章中一起禁用Pundit(你可以用Devise和Active Admin禁用Pundit吗?)但是这样做会很好.
UPDATE
我已经解决了,但我仍然不知道这是否应该开箱即用,我有一些奇怪的问题导致所有这一切.要点已更新.
我最终使用:
https://viget.com/extend/8-insanely-useful-activeadmin-customizations
还有一点:
有条件的before_action/before_filter的文档
以下是一点答案.我在过滤器中使用过强制AA来强制AA对AA内的资源和集合进行授权.接下来是添加策略范围,但我的大脑现在伤得太厉害了.
我还必须添加另一个过滤器来绕过仪表板上的身份验证,因为它是无头的.到目前为止似乎工作.
更新2
嗯......我想我说的太快了.这一切都只有在我作为常规登录时才有效User- 如果我退出,它会再次崩溃.
我有一个 div,其中包含网站导航中的选项卡表格。我将 div 设置为在移动设备中溢出,如下所示:
我想让 div 自动滚动到当前隐藏的活动选项卡,如下所示:
在另一个 SA 问题中,建议使用scrollIntoView. 在控制台测试了一下,效果很好:
document.getElementById("active_tab").scrollIntoView({block: "end"})
Run Code Online (Sandbox Code Playgroud)
我什至使用了 jQuery 版本scrollintoview:
$('#active_tab').scrollintoview();
Run Code Online (Sandbox Code Playgroud)
而且效果很好。问题是,当我将实际代码(任一代码)添加到我的网站时,溢出 div 会滚动一些随机量(似乎是一半)。这是一个例子:
在 Chrome 和 Safari 中尝试过此操作。我错过了一些明显的东西吗?我并不是想滚动整个页面 - 只是那个隐藏了溢出的 div 。非常奇怪的是,它直接在控制台中工作,但不能直接在我的代码中工作,并且对于 JS 和 JQ 都是如此。据我所知,没有其他 JS 等与此 div 等相关。
只是在玩构建 Rails 应用程序,我很确定我做了一些愚蠢的事情。我跑了一个脚手架,把模型 Ave vs Afe 拼错了。我确信我经历并更改了迁移文件和查看文件等中的所有内容,甚至搜索了“ave”以查看是否遗漏了任何内容。无论如何运行迁移,现在我明白了:
PG::UndefinedTable: ERROR: relation "aves" does not exist LINE 5: WHERE a.attrelid = '"aves"'::regclass ^ : SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum WHERE a.attrelid = '"aves"'::regclass AND a.attnum > 0 AND NOT a.attisdropped ORDER BY a.attnum
Extracted source (around line #17):
15 # GET /afes/new
16 def new
17 @afe = Afe.new
18 end
19
20 …Run Code Online (Sandbox Code Playgroud) 我正在将 Fullcalendar 安装更新到 V4。我通过 JSON 提供数据,并且我的活动标题中有 HTML(一些 FontAwsome 图标)。这是我用来渲染元素的旧 V3 代码:
$(function() {
$('#calendars').fullCalendar({
events: '/activities/calendar.json',
contentHeight: 750,
displayEventTime: false,
header: {
left: '',
center: 'title',
right: 'today prev,next'
},
businessHours: {
dow: [1, 2, 3, 4, 5]
},
handleWindowResize: true,
eventLimit: 2,
eventLimitClick: 'popover',
eventRender: function(event, element) {
element.find('.fc-title').html(event.title);
}
});
});
Run Code Online (Sandbox Code Playgroud)
这eventRender:就是失败的原因。新文档没有清楚地解释我如何将其转换为新版本。使用此代码后,我的日历根本无法加载,并在控制台中出现 json 解析错误。如果我删除它,它可以工作,但我的 HTML 会呈现为纯文本。我确信我在这里遗漏了一些明显且简单的东西。我的 JS 技能不太好。
我似乎无法在任何地方找到它 - 控制台显示该字段,nil但实际上操作文本正在存储可能为“空白”的内容。
MyModel.rich_text_field.nil?无论实际内容是否为空,都返回 false。
正在对 ES 进行故障排除,并想我会尝试升级到 7.10.2:
Dans-MacBook-Pro:~ aximus$ brew services restart elasticsearch
Stopping `elasticsearch`... (might take a while)
==> Successfully stopped `elasticsearch` (label: homebrew.mxcl.elasticsearch)
==> Successfully started `elasticsearch` (label: homebrew.mxcl.elasticsearch)
Run Code Online (Sandbox Code Playgroud)
启动失败:
Dans-MacBook-Pro:~ aximus$ tail -f /usr/local/var/log/elasticsearch.log
error:
Unrecognized VM option 'UseConcMarkSweepGC'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
at org.elasticsearch.tools.launchers.JvmErgonomics.flagsFinal(JvmErgonomics.java:126)
at org.elasticsearch.tools.launchers.JvmErgonomics.finalJvmOptions(JvmErgonomics.java:88)
at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:59)
at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:137)
at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:95)
Run Code Online (Sandbox Code Playgroud)
我尝试重新安装并链接 openjdk@11 (11.0.10) 但没有成功。目前死在水中:
Dans-MacBook-Pro:~ aximus$ curl 127.0.0.1:9200
curl: (7) Failed to connect to …Run Code Online (Sandbox Code Playgroud) 我已经阅读了文档(即你必须自己初始化它们)并看到许多关于需要这样的东西的答案:
$(document).ready(function() {
$('[data-toggle=tooltip]').tooltip();
});
$(document).ready(function() {
$('[data-toggle=popover]').popover();
});
Run Code Online (Sandbox Code Playgroud)
在你的代码中(这是在我的application.js中)让Bootstrap工具提示和弹出窗口等工作.
我也看到提到如果你有bootstrap.js文件包含这是不需要的.
无论哪种方式,我仍然无法加载工具提示或弹出窗口.我将两个示例直接粘贴到我的主布局文件中:
<button type="button" class="btn btn-lg btn-danger" data-toggle="popover" title="Popover title" data-content="And here's some amazing content. It's very engaging. Right?">Click to toggle popover</button>
<button type="button" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Tooltip on top">Tooltip on top</button>
Run Code Online (Sandbox Code Playgroud)
但他们仍然无法工作.我无法弄清楚我错过了什么.模态工作,所以我知道我已经加载了bootstrap.js.
我有一个简单的rails应用程序,我试图通过Capistrano回复.该应用程序在开发中工作正常但在部署时失败.我将其追溯到资产:预编译步骤,在本地计算机上也失败了.我已经看到了其他类似问题的其他帖子,但没有任何真正指向我正确的方向.
我不够强大,无法确定下一步的位置,所以任何指针都会受到赞赏.
Solara:myapp dan$ rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
rake aborted!
NoMethodError: undefined method `tr' for nil:NilClass
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:37:in `initialize'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:270:in `new'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:270:in `resolve_url_connection'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:258:in `resolve_hash_connection'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:215:in `resolve_connection'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:139:in `resolve'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:151:in `block in resolve_all'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:150:in `each'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:150:in `resolve_all'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:69:in `resolve'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/core.rb:46:in `configurations='
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/railtie.rb:117:in `block (2 levels) in <class:Railtie>'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:27:in `each'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.2.4/lib/active_record/railtie.rb:116:in `block in <class:Railtie>'
/Users/dan/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.2.4/lib/rails/initializable.rb:30:in …Run Code Online (Sandbox Code Playgroud) 我正在使用axlxs和axlsx_rails。我可以毫无问题地创建内联电子表格 - 例如我有一个index.xlsx.axlsx文件等。
问题是我有另一个操作使用完全相同的代码,所以我尝试创建一个部分_export.xlsx.axlsx并将我的代码移动到那里。然后我替换index.xlsx.axlsx为render 'export'.
我收到一个由 Excel 生成的 Excel 电子表格,显示它已损坏。我可以将我的代码复制到另一个文件中,但必须有一种更简单的方法来做到这一点。
javascript ×2
jquery ×2
actiontext ×1
activeadmin ×1
axlsx ×1
capistrano ×1
carrierwave ×1
devise ×1
fullcalendar ×1
homebrew ×1
pundit ×1
searchkick ×1
trix ×1