2013-06-14 6 views
11

私はアプリケーションをRails 4にアップグレードしていますが、この方法で何が問題なのか理解できていません。犯罪者は、updateメソッドです:submitをクリックRails 4:このメソッドで何が問題になっていますか?

def update 
    respond_to do |format| 
    if @doc.articles.find_index { |a| a.changed? } 
     @doc.publications.destroy_all 
    end 
    if @doc.update_attributes(params[:doc]) 
     @doc.create_activity :update, owner: current_user 
     if current_user.brand.editable? && params[:editing] 
     format.html { redirect_to editing_url(@doc) } 
     else 
     format.html { redirect_to share_url(@doc.user.ftp, @doc) } 
     end 
    end 
    end 
end 

は、このエラーを生成します。

ActionController::UnknownFormat in DocsController#update 

とハイライトこのライン:

:createメソッドが正常に動作します

respond_to do |format| 

、それはこのようになります

def create 
    @doc = Doc.new(params[:doc]) 
    respond_to do |format| 
    if @doc.save 
     @doc.create_activity :create, owner: current_user 
     if current_user.brand.editable? && params[:editing] 
     format.html { redirect_to doc_editing_url(@doc) } 
     else 
     format.html { redirect_to share_url(@doc.user.ftp, @doc) } 
     end 
    else 
     format.html { render action: "new" } 
    end 
    end 
end 

私は完全に立ち往生している。

ああ、私はそれはそれではないですので、あまりにもbefore_actionとして、このプライベートメソッドを持っている:

private 

def set_document 
    @doc = Doc.find(params[:id]) 
end 

EDIT

私はこの準説明が見つかりました:

In Rails 4.0, ActionController::UnknownFormat is raised when the action doesn't handle the request format. By default, the exception is handled by responding with 406 Not Acceptable, but you can override that now. In Rails 3, 406 Not Acceptable was always returned. No overrides.

私はそれがルートと関係があると思うようにしますが、もし私がそうそう宣言したら私のルートはデフォルトになるはずです。

resources :docs, :except => [:new, :show] do 
    get "adjust/:state" => "docs#adjust", :as => :adjust 
    patch "editing" => "docs#editing", :as => :editing 
    patch "reupdate/" => "docs#reupdate", :as => :reupdate 
    get "pdf" => "docs#pdf", :as => :pdf 
    collection { post :sort } 
end 

EDIT 2

すなわち、コントローラにJSONを追加:

format.html { redirect_to share_url(@doc.user.ftp, @doc) } 
format.json { render action: 'share', status: :created, location: @doc } 

は私に無い方法エラーを与え、編集ページに戻って私をリダイレクトするようだ:

Showing .../fin/app/views/docs/_form.html.erb where line #19 raised: 
undefined method `covers?' for nil:NilClass 

ここでは何が起こっているのかわかりません。

+2

フォームに 'remote:true'がありますか?それはJSを介して送信されますか?あなたのコントローラに 'respond_to:json'がありますか? – phoet

+0

フォームには 'remote:true'はありません.JS経由では送信されません。コントローラーには「respond_to:json」はありません。わかっている限り、私はそれが必要ではないからです。 –

答えて

2

考えられる理由の1つは、@doc.update_attributes(params[:doc])falseを返した場合、更新メソッドで実行中の書式ブロックが存在しない可能性があります。

通常、この場合はeditアクションがレンダリングされます。

1

HTMLのみを提供している場合は、respond_toformat.htmlはまったく必要ありません。

関連する問題