12得票3回答
在Rails中,如何销毁“联接表项”,而不删除实际记录?

我现在很困惑,不知道如何在连接表中删除/销毁记录: class Task < ActiveRecord::Base belongs_to :schema belongs_to :to_do end class Todo < ActiveRecord::Base be...

12得票2回答
Rails 4.0.3中的Active-Admin多选框无法保存

我正在使用rails 4.0.3尝试在Active-Admin中设置多对多的复选框,但复选框选择未被保存。这是我所拥有的:class Product < ActiveRecord::Base has_many :categorizations has_many :categori...

11得票5回答
Ruby on Rails在保存之前有许多通过关联对象。

在一个Ruby on Rails项目中,我正在尝试在将所有内容保存到数据库之前访问ActiveRecord上的关联对象。class Purchase < ActiveRecord::Base has_many :purchase_items, dependent: :destroy...

11得票1回答
使用Rails的reform gem,如何填充一个has_many:through嵌套模型?

我有一个用户模型和角色模型,通过ActiveRecord连接:has_many roles, through: :role_accounts 我希望有一个“编辑用户”屏幕,其中包含一个复选框列表,每个角色对应一个复选框。使用Reform gem(v2.1.0),这是表单对象的一部分:class...

11得票1回答
Activeadmin formtastic 动态选择

我希望通过Activeadmin的formtastic创建动态选择选项,如下所示: form do |f| f.inputs "Exam Registration Details" do f.input :user_id, :as => :select, :coll...

11得票2回答
在Ruby on Rails中,在一个belongs_to关联上设置一个has_many :through关联

我有三个模型,每个模型都具有以下关联:class Model1 < ActiveRecord::Base has_many :model2s has_many :model3s end class Model2 < ActiveRecord::Base belongs...

11得票2回答
Rails使用source和source_type对多个类型进行has_many through别名设置

所以这里有一个示例类class Company < ActiveRecord::Base has_many :investments has_many :vc_firms, through: :investments, source: :investor, source_...

11得票3回答
检测Rails中has_many:through关系的更改

我有一个模型,其中有许多has_many和has_many :through模型关系。例如,在我的User类中,我有: has_many :languages, through: :profile_languages 我希望能够使用'User.changes'函数检测到它们何时被添加或删除...

10得票2回答
如何在has_many through联接表中填充字段

我有一个问题涉及到Active Record关联,参考了Rails文档中的这一部分: http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association 如果我们有三个模型:class...

10得票2回答
多对多关系中的多态HasManyThrough关系

在我的 Laravel 应用程序中,我有以下类:class Product extends Model { public function extended() { return $this->morphTo(); } public fu...