Ruby on rails 在rails中使用form_实现一对一关系模型
我有一对一的用户模型和配置文件 以下是设备创建的Ruby on rails 在rails中使用form_实现一对一关系模型,ruby-on-rails,devise,form-for,belongs-to,has-one,Ruby On Rails,Devise,Form For,Belongs To,Has One,我有一对一的用户模型和配置文件 以下是设备创建的用户模型的代码。 现在我有了一个注册时创建的用户的基本档案。现在,我如何使用helper设备来编辑用户配置文件?该设备为当前用户提供了表单,用于?我们做了如下操作: #app/models/user.rb Class Model < ActiveRecord::Base before_create :build_profile end #config/routes.rb resources :users do resourc
用户
模型的代码。
现在我有了一个注册时创建的
用户的基本档案
。现在,我如何使用helper设备来编辑用户配置文件?该设备为当前用户提供了表单,用于?我们做了如下操作:
#app/models/user.rb
Class Model < ActiveRecord::Base
before_create :build_profile
end
#config/routes.rb
resources :users do
resources :profiles
end
#app/views/profiles/edit.html.erb
<%= form_for @profile do |f| %>
<%= f.hidden_field :user_id, current_user.id %>
<%= f.text_field :your_profile_options %>
<% end %>
这是一个非常基本的方法,但希望能给你更多的想法。如果你想在野外看到这一点,请查看(它使用Desive来处理用户,并且还有额外的“配置文件”模型)
#app/models/user.rb
Class Model < ActiveRecord::Base
before_create :build_profile
end
#config/routes.rb
resources :users do
resources :profiles
end
#app/views/profiles/edit.html.erb
<%= form_for @profile do |f| %>
<%= f.hidden_field :user_id, current_user.id %>
<%= f.text_field :your_profile_options %>
<% end %>