路由表单更新操作?

时间:2012-05-14 14:11:54

标签: ruby-on-rails ruby-on-rails-3

我有一个自定义的'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 =&gt;的简单案例。 “更新”到我的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"}

2 个答案:

答案 0 :(得分:2)

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

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

form_for(@release, :html => { :multipart => true }) do |f|

答案 1 :(得分:0)

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

:url => { :action => "update" }