Ruby on rails 如何在注册后使用Desive的ROR应用程序中初始化嵌套表单属性?
我是RubyonRails的新手,正在构建一个应用程序,用户可以在注册后添加他的教育历史。我使用两个编辑表单,一个默认设计编辑视图用于密码或电子邮件更新,另一个编辑用户视图是我与users\u controller一起创建的,用于更新名称等其他字段。我使用嵌套表单添加教育详细信息。问题是我如何初始化教育模型,因为我希望用户在注册后添加教育详细信息。我不希望用户在“注册”字段中用所有这些字段提示用户。 没有错误,但没有显示教育领域 主要问题是,我正在使用Desive for registration和自定义编辑表单来添加教育字段。我需要编写自定义的新方法吗 以下是我的应用程序/views/users/edit.html.erb中的代码Ruby on rails 如何在注册后使用Desive的ROR应用程序中初始化嵌套表单属性?,ruby-on-rails,ruby-on-rails-4,devise,Ruby On Rails,Ruby On Rails 4,Devise,我是RubyonRails的新手,正在构建一个应用程序,用户可以在注册后添加他的教育历史。我使用两个编辑表单,一个默认设计编辑视图用于密码或电子邮件更新,另一个编辑用户视图是我与users\u controller一起创建的,用于更新名称等其他字段。我使用嵌套表单添加教育详细信息。问题是我如何初始化教育模型,因为我希望用户在注册后添加教育详细信息。我不希望用户在“注册”字段中用所有这些字段提示用户。 没有错误,但没有显示教育领域 主要问题是,我正在使用Desive for registratio
<div class="input-field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<div class="input-field">
<%= f.label :date_of_birth %><br />
<%=f.date_field(:date_of_birth, :class => "datepicker")%>
</div>
<div class="input-field">
<%= f.label :city %><br />
<%= f.text_field :city, autofocus: true %>
</div>
<div class="input-field">
<%= f.label :about_me %>
<%= f.text_area :about_me, autofocus: true %>
</div>
<%= f.fields_for :educations do |ff| %>
<div>
<%= ff.label :institution_name %>
<%= ff.text_field :institution_name %>
</div>
<div>
<%= ff.label :course %>
<%= ff.text_field :course %>
</div>
<div class="input-field">
<%= f.label :from %><br />
<%=f.date_field(:from, :class => "datepicker")%>
</div>
<div class="input-field">
<%= f.label :to %><br />
<%=f.date_field(:to, :class => "datepicker")%>
</div>
<% end %>
<%= f.submit "Save changes"%>
<% end %>
另外,我尝试使用formhelper函数,但没有任何帮助。在
新建
或编辑
操作中,您可以构建教育
对象,它将初始化嵌套属性。如下-
def new
current_user.eductions.build #or @user.educations.build
# it will initialize a eduction object in form
end
你能用服务器日志中生成的
params
更新这个问题吗?我试过了,但没有帮助。由于Desive处理用户注册,所以从未调用新操作,所以从未调用新方法,但我还是按照您的建议尝试了这个方法。我还尝试将代码行放入edit方法,但仍然不起作用我在UsersController中得到了一个NoMethodError#edit else match=match_attribute_method?(method.to_s)match?缺少属性(匹配、*参数和块):超级结束
class Education < ActiveRecord::Base
belongs_to :user, inverse_of: :educations
validates_presence_of :user
end
!ruby/hash:ActionController::Parameters
utf8: "✓"
_method: patch
authenticity_token:1gHK22TcGLsPjIdb/
user: !ruby/hash:ActionController::Parameters
name: ''
date_of_birth: '1992-03-03'
city: delhi
about_me: i am what i am!!
commit: Save changes
controller: users
action: update
id: '3'
def new
current_user.eductions.build #or @user.educations.build
# it will initialize a eduction object in form
end