Ruby on rails 使用类变量
这里是初学者,通过跳入项目学习RubyonRails。这个问题可能是纯ruby的,与rails无关。我还要注意,我使用的是Active_Admin 我有以下两类:所有者和电话Ruby on rails 使用类变量,ruby-on-rails,ruby,formtastic,Ruby On Rails,Ruby,Formtastic,这里是初学者,通过跳入项目学习RubyonRails。这个问题可能是纯ruby的,与rails无关。我还要注意,我使用的是Active_Admin 我有以下两类:所有者和电话 class Owner < ActiveRecord::Base attr_accessible :email, :password, has_many :phones end class Phone < ActiveRecord::Base attr_accessible :owner_id :
class Owner < ActiveRecord::Base
attr_accessible :email, :password,
has_many :phones
end
class Phone < ActiveRecord::Base
attr_accessible :owner_id :model
belongs_to :owner
end
看起来我应该在跳入rails之前回顾一下pickaxe的书并完善我的ruby
感谢将用户和手机放在一个表单中,您的表单应该如下所示:
form_for @phone do |phone_form|
phone_form.label :model
phone_form.text_field :model
fields_for @phone.owner do |owner_fields|
owner_fields.label :email
owner_fields.text_field :email
如果使用此方法,请确保通过在
手机
模型上设置,可以从手机
模型更新所有者
。在这种情况下,应使用嵌套形式
。railscast中很好地解释了嵌套表单的用法
form_for @phone do |phone_form|
phone_form.label :model
phone_form.text_field :model
fields_for @phone.owner do |owner_fields|
owner_fields.label :email
owner_fields.text_field :email