Ruby on rails 我如何解决此设计身份验证挑战?

Ruby on rails 我如何解决此设计身份验证挑战?,ruby-on-rails,devise,Ruby On Rails,Devise,大家好,我在为用户设计身份验证方面遇到了一些挑战: 在我的应用程序中,我有两个名为color和sub_color的模型。sub_颜色属于颜色,并且颜色有很多sub_颜色。我已经在数据库中添加了适当的数据 挑战;我希望用户能够在Desive form_中选择这些,以便在注册为收集对象时使用,并且sub_颜色的id也将用于识别特定用户(例如,在这种情况下,我可以对所有使用蓝色的用户进行排序)。请问我如何做到这一点 这是我尝试过的,但不起作用: %= simple_form_for(resource

大家好,我在为用户设计身份验证方面遇到了一些挑战:

在我的应用程序中,我有两个名为color和sub_color的模型。sub_颜色属于颜色,并且颜色有很多sub_颜色。我已经在数据库中添加了适当的数据

挑战;我希望用户能够在Desive form_中选择这些,以便在注册为收集对象时使用,并且sub_颜色的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    
%=simple_form_for(资源,as:resource_name,url:registration_path(资源_name))do|f|%>


用户模型: 属于:子颜色 有一个:颜色,通过::子颜色 设计。。。。。。。 结束 亚色调模型 有很多:用户 属于:颜色 结束 颜色模型 有很多种颜色 结束
这是我在web浏览器上看到的错误

NoMethodError in Devise::Registrations#new
[undefined method `color_id' for #<User:0xbacc720>]

装置中的命名错误::注册#新 [用于#的未定义方法'color_id']
首先,您需要将
color\u id
sub\u color\u id
添加到用户表中

然后定义关联,在user.rb
中属于:sub\u color
并且在sub\u color.rb
中有多个:users
。同样,user.rb
属于:color
,并且在color.rb
中有许多:users


希望有帮助

您的用户模型中有
color\u id
sub\u color\u id
吗?没有,但它们现在已经存在。谢谢,但我仍然面临挑战,我使用RSB的答案将其添加到模型中。您能否与您的用户一起更新问题,颜色和亚颜色模型及其字段我已经完成了上述所有工作,谢谢,但它仍然没有显示任何方法错误。设计中的NoMethodError::Registrations#new show C:/Users/…../new.html.erb其中第19行出现了#Rails.root:C:/Users/C/Documents/Ojojas应用程序跟踪|框架跟踪|完整跟踪activemodel(4.2.6)lib/active_model/attribute_methods.rb:433:inmethod_missing'actionview(4.2.6)lib/action_view/helpers/tags/base.rb:28:invalue'actionview(4.2.6)lib/action_view/helpers/tags/base.rb:28:invalue'actionview(4.2.6)lib/action\u view/helpers/tags/collection\u select.rb:16:在“渲染中的块”中,这是因为需要删除颜色ID那么如何实现集合对象?请举个例子。我注意到用户的Sub_color_id字段中没有值。我为用户添加了它,现在可以访问它了。谢谢