Ruby on rails 在选择输入RubyonRails上循环
我试图在ruby on rails中对我的所有用户进行选择输入,这几乎可以实现,但问题是,用户无法获取我的用户用户名,但我呈现了如下内容: 我在控制台中创建了3个用户,在rails控制台上可以看到它们 我的控制器里有这个:Ruby on rails 在选择输入RubyonRails上循环,ruby-on-rails,ruby,Ruby On Rails,Ruby,我试图在ruby on rails中对我的所有用户进行选择输入,这几乎可以实现,但问题是,用户无法获取我的用户用户名,但我呈现了如下内容: 我在控制台中创建了3个用户,在rails控制台上可以看到它们 我的控制器里有这个: def new @bug = Bug.new @users = User.all end 还有我的情妇 def bug_params params.require(:bug).permit(:owner, :title, :descripti
def new
@bug = Bug.new
@users = User.all
end
还有我的情妇
def bug_params
params.require(:bug).permit(:owner, :title, :description)
end
在我的html中:
<%= form_with model: @bug do |form| %>
<%= form.select :owner, @users %>
<%= form.text_field :title, placeholder: "title" %>
<%= form.text_area :description, placeholder: "description" %>
<%= form.submit %>
<% end %>
有人能告诉我怎么了吗?使用select form helper,您只返回一组用户实例
如中所述,您需要收集要作为选项值和选项显示传递的用户属性。
例如:
<%= form.select :owner, @users.collect {|u| [ u.name, u.id ] } %>
#=> output
# <select name="bug[owner]">
# <option value="1">John</option>
# <option value="2">Joe</option>
# </select>
使用select form helper,您只返回用户实例的集合
如中所述,您需要收集要作为选项值和选项显示传递的用户属性。
例如:
<%= form.select :owner, @users.collect {|u| [ u.name, u.id ] } %>
#=> output
# <select name="bug[owner]">
# <option value="1">John</option>
# <option value="2">Joe</option>
# </select>
用于从记录集合中创建选择
<%= form_with model: @bug do |form| %>
<%= form.collection_select(:owner, @users, :id, :name) %>
<%= form.text_field :title, placeholder: "title" %>
<%= form.text_area :description, placeholder: "description" %>
<%= form.submit %>
<% end %>
用于从记录集合中创建选择
<%= form_with model: @bug do |form| %>
<%= form.collection_select(:owner, @users, :id, :name) %>
<%= form.text_field :title, placeholder: "title" %>
<%= form.text_area :description, placeholder: "description" %>
<%= form.submit %>
<% end %>
是否在用户类中定义了to_s方法?是否在用户类中定义了to_s方法?