如何在哈希中显式设置键和值,然后在选择中使用它们?我有一个可以保存外部链接的链接模型。链接有标题和网址。我想使用标题作为键和 url 作为值。
- - - - - - - - - - - 更新 - - - - - - - - - - - - -
这个作品。。
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