如何顯式設置密鑰和哈希值,然後使用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