问题标签 [activesupport-concern]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ruby - 为什么/如何 ActiveSupport::Concern 更改祖先查找顺序?
考虑以下代码:
为什么通过 AS::Concern 与普通 Ruby 包含的模块的祖先顺序不同?
ruby-on-rails - 关注所包含的测试 belongs_to
我有一个模型
在 DB调查表中有下一个字段:
- 响应保存日期
- response_saved_by_type
- response_saved_by_id
和模块
根据这篇博文https://semaphoreci.com/community/tutorials/testing-mixins-in-isolation-with-minitest-and-rspec,我尝试为 Respondable 问题编写单元测试,单独测试它
这是我的rspec:
当我运行测试时,我收到下一个错误:
ruby-on-rails - Rails 5, Concerns - can they reference a database table?
I'm trying to learn about concerns.
Most of the blog posts and examples I can find discuss them in the context of moving class methods defined in a model to a common repository. I understand that part.
I don't understand whether concerns can be used to reduce the setup for associated models. For example, I have a user model and an organisation model. Each of user and organisation will have an address.
If address is a model, it will be polymorphic and belong to addressable. Then user and organisation will each have one address.
I am trying to understand whether I can make address a concern and then include it in my user and organisation models. If so, can I still have a table in the database called address? It's not clear to me whether I can have the db table if I don't have a model called address (which I wouldn't need if I used concerns subfolder in the models folder to define address).
ruby-on-rails - Rails 5,关注点 - 如何在表单中使用方法
我正在尝试学习如何在我的 Rails 5 应用程序中使用模型关注点。
我有一个嵌套模型:
在我的模型/关注文件夹中,我有:
然后在我的成本嵌套形式中,我有:
当我尝试呈现组织表单(使用嵌套成本字段)时,我收到一条错误消息:
为了能够在我的嵌套表单中使用 HasCostPolicy 关注点,我需要做什么?
ruby-on-rails - Rails 5 中未加载关注点
我有一个基本的 Rails 应用程序,我正在尝试将关注点用于干燥模型。在开发环境中一切正常,但是当我尝试将应用程序上传到 Heroku 时,它不断给我这个错误:
我试图禁用急切加载,但没有帮助。
这是我的地址模型:
这是我命名为“persistable”的模块,位于app/models/concerns/persistable.rb
我已经做了什么:
- 试图关闭急切加载
- 试图将
Persistable
模块移出concerns
目录 - 试图包含
concerns
自动加载配置的路径
没有任何效果,我仍然有这个问题!
更新
我做了命令表单指南 rails r 'puts ActiveSupport::Dependencies.autoload_paths'
来检查 autoload_paths,我得到了:
ruby-on-rails - Extending Rails 4 engine models with concerns
I am trying to extend a model from engine 1 with a concern from engine 2 through an app initializer, but I'm getting some weird behavior, here's what I've got:
Concern
Initializer
When I boot up the application, I see as expect the Concern included!
message in the console, and the Member
class can call the method jump
, but as soon as I change any code in the host app I get the following error:
NoMethodError (undefined method 'jump' for #<Engine1::Member:0x007fe7533b4f10>)
and I have to reload the server, then it works fine again until I make another change in the host app, then it throws the error again, why is this happening and how can I avoid it?
Is there a better place where I should perform the class opening to include the concern instead of the initializer?
ruby-on-rails - Rails 委托和别名 - 无限循环?
我不明白以下涉及delegate
和的无限循环alias
我有一家Employee
失踪的公司,我有以下无限循环
ruby-on-rails - 通过 ActiveSupport::Concern 或自定义验证进行 Rails 动态模型验证
所以...
我目前正在开发一个 Rails 项目,该项目将创建几个具有相似费用属性的模型。我想做的是创建一个可重用的验证机制。例如,我的模型可能是..
...并且我将有几个结构相似的模型(每项费用总是有两个不同的方面),我想验证费用是非负数、有效数字,并且生产者费用总是低于相应的消费费用。请注意,跨模型的不同属性可能命名完全不同,但可以假设生产者/消费者费用对总是命名相同,除了前缀。关于如何实现这一点的任何提示都会很棒。
ruby-on-rails - 如何修复 Heroku / Ruby 上的错误“自动加载常量时检测到循环依赖”
部署后,我在 Heroku 上收到此错误,但我没有收到错误或在本地遇到此问题。
以下命名/命名空间等有什么问题?我错过了什么?
模型/关注/购买/finalize_utils.rb
模型/购买.rb
日志错误:
ruby-on-rails - Rails 5.0.1 - Friendly_id gem - 包含主动关注模块 before_create 或 before_save
我创建了这个模块:
应用程序/模型/关注/sluggable.rb
我将它包含在模型中,如下所示:
应用程序/模型/plan.rb
但 before_create 不会触发。slug 列是 not_null 列,因此出现数据库错误。
错误:“slug”列中的空值违反非空约束
如果将 set_slug 代码直接放在模型中,它可以工作。那么我在这里缺少关于 Rails 5 中的关注点的什么?
我想知道它是否与使用 FriendlyId 有关(这就是我首先添加 slug 的原因!)