我正在尝试创建一个 Collaboration在我的Rails 4项目中表,但我遇到了一个问题.我希望它属于单个用户,合作者.
我运行以下命令来生成模型和迁移,我也在下面复制了它.
rails generate model Collaboration project:references collaborator:references accepted:boolean
Run Code Online (Sandbox Code Playgroud)
移民:
class CreateCollaborations < ActiveRecord::Migration
def change
create_table :collaborations do |t|
t.references :project, index: true, foreign_key: true
t.references :collaborator, index: true, foreign_key: true
t.boolean :accepted
t.timestamps null: false
end
end
end
Run Code Online (Sandbox Code Playgroud)
模型:
class Collaboration < ActiveRecord::Base
belongs_to :project
belongs_to :collaborator, class_name: 'User'
end
Run Code Online (Sandbox Code Playgroud)
我更新了Collaboration模型,, class_name: 'User'如上所示.同样,我更新了现有Strategy模型以包含ahas_many :collaborations
class Project < ActiveRecord::Base
has_many :collaborations
end
Run Code Online (Sandbox Code Playgroud)
当我运行时rake db:migrate,我收到以下错误报告.
rake aborted!
StandardError: An error …Run Code Online (Sandbox Code Playgroud) ruby ruby-on-rails associations rails-migrations rails-activerecord
我将我的一个应用程序更新到了 Rails 5,并将 Ruby 版本也升级到了 2.3.1。该应用程序在 Rails 5 升级之前就已经使用了 Puma,并部署在 Digital Ocean Droplet 上。
当我rails server在本地启动时,我会在 Rails 日志中获得正常输出,我将其复制到下面。
=> Booting Puma
=> Rails 5.0.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
[14669] Puma starting in cluster mode...
[14669] * Version 3.4.0 (ruby 2.3.1-p112), codename: Owl Bowl Brawl
[14669] * Min threads: 5, max threads: 5
[14669] * Environment: development
[14669] * Process workers: 2
[14669] * Preloading application
[14669] * …Run Code Online (Sandbox Code Playgroud) 我有命名空间的模型,例如:
class Vehicle < ActiveRecord::Base; end
class Vehicle::Car < Vehicle; end
class Vehicle::Train < Vehicle; end
class Vehicle::Jet < Vehicle; end
Run Code Online (Sandbox Code Playgroud)
在为这些模型创建工厂时,它们的设置方式如下:
factory :vehicle_car, class: Vehicle::Car do; end
factory :vehicle_train, class: Vehicle::Train do; end
factory :vehicle_jet, class: Vehicle::Jet do; end
Run Code Online (Sandbox Code Playgroud)
这会产生以下弃用警告:
弃用警告:不推荐按类查找工厂,并将在 5.0 中删除。改用符号并设置 FactoryBot.allow_class_lookup = false。
是否有编写符号来命名这些工厂的格式,以便我不需要使用类名来遵守弃用警告?
我无法弄清楚如何将 npm 包添加到我的 elixir/phoenix 项目中,这些包不是专门为与 brunch 一起使用而构建的。
我不想做的一件事是手动将文件从 复制node_modules/到vendor/。
如果有人知道如何正确配置 Brunch 以在 Phoenix 应用程序中使用 Tailwind,我们将不胜感激。
我正在开发一个项目,需要在表中创建动态查询过滤规则,以用于过滤另一个表中的数据。我需要一些帮助来看看这是否可行,如果可行,如何形成查询。
people rules
+----+--------+-----+ +----+--------+-------+----------+----------+
| id | name | age | | id | type | field | operator | criteria |
+----+--------+-----+ +----+--------+-------+----------+----------+
| 1 | Emma | 34 | | 1 | people | age | > | 30 |
| 2 | Larry | 25 | +----+--------+-------+----------+----------+
| 3 | Alice | 22 |
| 4 | Thomas | 31 |
+----+--------+-----+
Run Code Online (Sandbox Code Playgroud)
在此示例中,我想通过使用“rules”表中的条件来查询“people”表。我读到了 PostgreSQL 中的通用表表达式,并认为我可以在这里使用它,但到目前为止我还没有成功。到目前为止,这是我尝试过的:
WITH cte_rule AS (SELECT field FROM rules WHERE id = 1) …Run Code Online (Sandbox Code Playgroud) ruby ×3
activerecord ×1
associations ×1
brunch ×1
elixir ×1
factory-bot ×1
postgresql ×1
puma ×1
sass ×1
sql ×1
tailwind-css ×1