2016-02-02 41 views

回答

0

我現在明白你的意思了。毫無疑問,你有很多方法可以完成這種事情。我喜歡的方式是這樣做的控制器:

@type_pages = TypePage.all.collect do |type_page| 
    [type_page.name, type_page.id] 
end.unshift(['Pagina Principal', 0]) 

然後,當你在表單助手是你html.erb你可以使用:

<%= f.select :type_page_id, @type_pages %> 
+0

**我需要添加一個值,是不是在我的數據庫這樣的事情,但我得到的錯誤sintaxys默認選擇:| T **'{| [t.name,t.id],[「Pagina Principal」,0]}' – DAES

0

假設你正在努力使Pagina Principal的從@type_pages

<%= f.select :type_page_id, @type_pages.map(&:name), selected: "Pagina Principal" %>