如何显式设置密钥和哈希值,然后使用select?我有一个链接模型,可以保存外部链接。一个链接有一个标题和一个网址。我想使用标题作为键和url作为值。显式设置键和值的选择
--------------------- UPDATE ------------------------ -
这项工作..
links = Link.all
link_array = []
links.each do |link|
link_array << [link.title,link.url]
end
但是,现在这里是顺利。我想将此数组连接到另一个数组,以便可以从单个表单选择中选择两个模型。像这样...
a = PagesController.action_methods
# this grabs each action from the pages controller that will later be used as a route
b = a.select {|s| s.include? "callback"}
c = a - b
# b and c removes any position in the array that includes the word 'callback' so that only actions defined in the controller are returned
links = Link.all
link_array = []
links.each do |link|
link_array << [link.title,link.url]
end
@all_links = c + link_array
# desired result is an array used in a single form select containing both external links and internal links