我目前正在尝试使用嵌套表单在您创建歌曲时将类别标签添加到歌曲中。在我向它添加嵌套属性之前,该表单工作正常,现在提交按钮在您单击它时不执行任何操作(页面不会重新加载或任何操作)。
在我的模型中,尽管分类,歌曲有很多类别,反之亦然。
这是表格:
<div class="span10 offset1">
<%= form_for(@song) do |f| %>
<%= f.label :title, "Title" %>
<%= f.text_field :title %>
<%= nested_form_for(@song.categorizations.build) do |f| %>
<%= f.label :category_id, "TAG" %>
<%= f.select :category_id, options_for_select(Category.all.collect {|c| [ c.tag, c.id ] }, { :include_blank => true }), prompt: "" %>
<%end%>
<%= f.submit "Save song", class: "btn btn-large btn-primary" %>
<% end %>
</div>
还有我的歌曲控制器:
def new
@song = Song.new
end
def create
@song = Song.new(params[:song])
if @song.save
flash[:success] = "Song successfully added to library"
redirect_to @song
else
#FAIL!
render 'new'
end
end
分类控制器:
def new
@categorization = Categorization.new
end
def create
@song = Song.find(params[:id])
@categorization = Category.new(params[:categorization])
if @categorization.save
flash[:success] = "Tag added!"
redirect_to song_path(@song)
else
flash[:fail] = "TAG ERROR"
redirect_to edit_song_path(@song)
end
end
预先感谢您的任何帮助!