我有一个 Rails 项目,它有一个简单的映射关系,如下所示:
型号类别
has_many :stories
模特故事
belongs_to category
在我的故事控制器中,我有
def new
@story = Story.new
@categories = Category.all
end
然后在我的 new.html.erb 我有
<%= form_for @story do |f| %>
<%= f.text_field, :title %>
<%= collection_select(:story, :category_id, @categories, :id, :name)%>
<% end %>
我想<%= collection_select %>
用(文本字段)替换(选择框)<%= f.text_field%>
并使用 jquery toxeninput javascript 插件填充数据,但我不知道该怎么做。