你好人我在这里有一些挑战与用户的设计认证:我该如何解决这种设计认证挑战?
我有两个模型叫我的应用程序中的颜色和sub_color。 sub_color belongs_to颜色和颜色has_many sub_colors.I已经用适当的数据在数据库中播种
挑战;我希望用户能够在设计form_for中选择这些,当他们注册为集合对象时,sub_color的id也将用于标识特定用户(例如,我可以将所有用户蓝色)。我该如何做到这一点?
这是我已经试过,但它不工作:
%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email, required: true, autofocus: true %>
<%= f.input :user_name, required: true %>
<%= f.input :password, required: true, hint: ("# {@minimum_password_length} characters minimum" if @minimum_password_length) %>
<%= f.input :password_confirmation, required: true %>
<%= f.input :first_name, required: true %>
<%= f.label :color_id, "Color" %> <br/>
<%= f.collection_select :color_id, Color.order(:name), :id, :name, include_blank: true%>
<%= f.label :sub_color_id, "Sub Color" %> <br/>
<%= f.grouped_collection_select :sub_color_id, Color.order(:name), :sub_color, :name, :id, :name, include_blank: true%>
<div class="form-actions">
<%= f.button :submit, "Sign up" %>
</div>
model for users:
belongs_to :sub_color
has_one :color, through: :sub_color
devise.......
end
model for sub_color
has_many :users
belongs_to :color
end
model for color
has_many :sub_color
end
这是我在网络浏览器中看到
NoMethodError in Devise::Registrations#new
[undefined method `color_id' for #<User:0xbacc720>]
你的用户模型中是否有'color_id'和'sub_color_id'? –
不,我没有它,但他们现在在..谢谢,但我仍然有挑战,我用RSB的答案将其添加到模型。 – Dlaw
您的用户,颜色和子颜色模型及其字段的更新问题 –