0

我有一个自定义的“trackupload”视图(这实际上只是我的编辑视图的一个变体)。我正在使用以下控制器操作来渲染它:

  def trackupload
    @release = Release.find(params[:release_id]) #Note: I had to use :release_id instead of :id, not sure why?
      respond_to do |format|
      format.html # show.html.erb
      format.json { render :json => @release }
      format.pdf { render :layout => false }
    end
  end

我的更新操作:

  def update
    @release = Release.find(params[:id])

    respond_to do |format|
      if @release.update_attributes(params[:release])
        format.html { redirect_to @release, :notice => 'Release was successfully updated.' }
        format.json { head :ok }
      else
        format.html { render :action => "edit" }
        format.json { render :json => @release.errors, :status => :unprocessable_entity }
      end
    end
  end

表格本身如下:

<%= form_for(@release, :action => "update", :html => { :multipart => true }) do |f| %>
<h3>Upload Tracks for <%= @release.title %></h3>
  <%= f.fields_for :tracks do |builder| %>
  <%= render 'upload_track_fields', :f => builder %>
   <% end %>
<%= f.submit "Upload Tracks", :class => "submit" %>
<% end %>

我想做的就是让它在提交时使用发布控制器的更新操作。我认为这是将 action => "update" 添加到我的 form_for 标记的简单案例,但它似乎不起作用。我没有错误,但没有任何反应。

知道缺少什么或我哪里出错了吗?

发布的 Rake 路由输出:

      autocomplete_artist_name_releases GET    /releases/autocomplete_artist_name(.:format)                                       {:action=>"autocomplete_artist_name", :controller=>"releases"}
                         release_artists GET    /releases/:release_id/artists(.:format)                                            {:action=>"index", :controller=>"artists"}
                                         POST   /releases/:release_id/artists(.:format)                                            {:action=>"create", :controller=>"artists"}
                      new_release_artist GET    /releases/:release_id/artists/new(.:format)                                        {:action=>"new", :controller=>"artists"}
                     edit_release_artist GET    /releases/:release_id/artists/:id/edit(.:format)                                   {:action=>"edit", :controller=>"artists"}
                          release_artist GET    /releases/:release_id/artists/:id(.:format)                                        {:action=>"show", :controller=>"artists"}
                                         PUT    /releases/:release_id/artists/:id(.:format)                                        {:action=>"update", :controller=>"artists"}
                                         DELETE /releases/:release_id/artists/:id(.:format)                                        {:action=>"destroy", :controller=>"artists"}
                          release_tracks GET    /releases/:release_id/tracks(.:format)                                             {:action=>"index", :controller=>"tracks"}
                                         POST   /releases/:release_id/tracks(.:format)                                             {:action=>"create", :controller=>"tracks"}
                       new_release_track GET    /releases/:release_id/tracks/new(.:format)                                         {:action=>"new", :controller=>"tracks"}
                      edit_release_track GET    /releases/:release_id/tracks/:id/edit(.:format)                                    {:action=>"edit", :controller=>"tracks"}
                           release_track GET    /releases/:release_id/tracks/:id(.:format)                                         {:action=>"show", :controller=>"tracks"}
                                         PUT    /releases/:release_id/tracks/:id(.:format)                                         {:action=>"update", :controller=>"tracks"}
                                         DELETE /releases/:release_id/tracks/:id(.:format)                                         {:action=>"destroy", :controller=>"tracks"}
                     release_trackupload GET    /releases/:release_id/trackupload(.:format)                                        {:action=>"trackupload", :controller=>"releases"}
                 release_releases_tracks GET    /releases/:release_id/releases_tracks(.:format)                                    {:action=>"index", :controller=>"releases_tracks"}
                                         POST   /releases/:release_id/releases_tracks(.:format)                                    {:action=>"create", :controller=>"releases_tracks"}
              new_release_releases_track GET    /releases/:release_id/releases_tracks/new(.:format)                                {:action=>"new", :controller=>"releases_tracks"}
             edit_release_releases_track GET    /releases/:release_id/releases_tracks/:id/edit(.:format)                           {:action=>"edit", :controller=>"releases_tracks"}
                  release_releases_track GET    /releases/:release_id/releases_tracks/:id(.:format)                                {:action=>"show", :controller=>"releases_tracks"}
                                         PUT    /releases/:release_id/releases_tracks/:id(.:format)                                {:action=>"update", :controller=>"releases_tracks"}
                                         DELETE /releases/:release_id/releases_tracks/:id(.:format)                                {:action=>"destroy", :controller=>"releases_tracks"}
                  release_product_tracks GET    /releases/:release_id/products/:product_id/tracks(.:format)                        {:action=>"index", :controller=>"tracks"}
                                         POST   /releases/:release_id/products/:product_id/tracks(.:format)                        {:action=>"create", :controller=>"tracks"}
               new_release_product_track GET    /releases/:release_id/products/:product_id/tracks/new(.:format)                    {:action=>"new", :controller=>"tracks"}
              edit_release_product_track GET    /releases/:release_id/products/:product_id/tracks/:id/edit(.:format)               {:action=>"edit", :controller=>"tracks"}
                   release_product_track GET    /releases/:release_id/products/:product_id/tracks/:id(.:format)                    {:action=>"show", :controller=>"tracks"}
                                         PUT    /releases/:release_id/products/:product_id/tracks/:id(.:format)                    {:action=>"update", :controller=>"tracks"}
                                         DELETE /releases/:release_id/products/:product_id/tracks/:id(.:format)                    {:action=>"destroy", :controller=>"tracks"}
    release_product_producttracklistings GET    /releases/:release_id/products/:product_id/producttracklistings(.:format)          {:action=>"index", :controller=>"producttracklistings"}
                                         POST   /releases/:release_id/products/:product_id/producttracklistings(.:format)          {:action=>"create", :controller=>"producttracklistings"}
 new_release_product_producttracklisting GET    /releases/:release_id/products/:product_id/producttracklistings/new(.:format)      {:action=>"new", :controller=>"producttracklistings"}
edit_release_product_producttracklisting GET    /releases/:release_id/products/:product_id/producttracklistings/:id/edit(.:format) {:action=>"edit", :controller=>"producttracklistings"}
     release_product_producttracklisting GET    /releases/:release_id/products/:product_id/producttracklistings/:id(.:format)      {:action=>"show", :controller=>"producttracklistings"}
                                         PUT    /releases/:release_id/products/:product_id/producttracklistings/:id(.:format)      {:action=>"update", :controller=>"producttracklistings"}
                                         DELETE /releases/:release_id/products/:product_id/producttracklistings/:id(.:format)      {:action=>"destroy", :controller=>"producttracklistings"}
             release_product_itunes_data GET    /releases/:release_id/products/:product_id/itunes_data(.:format)                   {:action=>"index", :controller=>"itunes_data"}
                                         POST   /releases/:release_id/products/:product_id/itunes_data(.:format)                   {:action=>"create", :controller=>"itunes_data"}
        new_release_product_itunes_datum GET    /releases/:release_id/products/:product_id/itunes_data/new(.:format)               {:action=>"new", :controller=>"itunes_data"}
       edit_release_product_itunes_datum GET    /releases/:release_id/products/:product_id/itunes_data/:id/edit(.:format)          {:action=>"edit", :controller=>"itunes_data"}
            release_product_itunes_datum GET    /releases/:release_id/products/:product_id/itunes_data/:id(.:format)               {:action=>"show", :controller=>"itunes_data"}
                                         PUT    /releases/:release_id/products/:product_id/itunes_data/:id(.:format)               {:action=>"update", :controller=>"itunes_data"}
                                         DELETE /releases/:release_id/products/:product_id/itunes_data/:id(.:format)               {:action=>"destroy", :controller=>"itunes_data"}
                        release_products GET    /releases/:release_id/products(.:format)                                           {:action=>"index", :controller=>"products"}
                                         POST   /releases/:release_id/products(.:format)                                           {:action=>"create", :controller=>"products"}
                     new_release_product GET    /releases/:release_id/products/new(.:format)                                       {:action=>"new", :controller=>"products"}
                    edit_release_product GET    /releases/:release_id/products/:id/edit(.:format)                                  {:action=>"edit", :controller=>"products"}
                         release_product GET    /releases/:release_id/products/:id(.:format)                                       {:action=>"show", :controller=>"products"}
                                         PUT    /releases/:release_id/products/:id(.:format)                                       {:action=>"update", :controller=>"products"}
                                         DELETE /releases/:release_id/products/:id(.:format)                                       {:action=>"destroy", :controller=>"products"}
                                releases GET    /releases(.:format)                                                                {:action=>"index", :controller=>"releases"}
                                         POST   /releases(.:format)                                                                {:action=>"create", :controller=>"releases"}
                             new_release GET    /releases/new(.:format)                                                            {:action=>"new", :controller=>"releases"}
                            edit_release GET    /releases/:id/edit(.:format)                                                       {:action=>"edit", :controller=>"releases"}
                                 release GET    /releases/:id(.:format)                                                            {:action=>"show", :controller=>"releases"}
                                         PUT    /releases/:id(.:format)                                                            {:action=>"update", :controller=>"releases"}
                                         DELETE /releases/:id(.:format)                                                            {:action=>"destroy", :controller=>"releases"}
4

2 回答 2

2

您可以删除:action => 'update'.

默认情况下,持久化记录指向此操作

form_for(@release, :html => { :multipart => true }) do |f|
于 2012-05-14T14:51:19.543 回答
0

尝试将您更改action => "update"为“:url”属性内:

:url => { :action => "update" }
于 2012-05-14T14:22:38.593 回答