2012-06-11 4 views
2

나는이 guide 다음, 레일 3.2 응용 프로그램에 JQuery와 파일 업로드를 설정하기 위해 노력하고있어 디버깅하는 방법에 대해 설명합니다. 내가 갖는 로그에서게시물 500 내부 서버 오류

POST http://testapp.dev/photos 500 (Internal Server Error) 

:

모든 것은 거의 내가가 크롬의 콘솔에 오류가 표시 클릭 "업로드를 시작"할 때 완벽하게 하지만을하고있다

ActionView::MissingTemplate (Missing template photos/create, application/create with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :coffee]}. 

컨트롤러를 통해 칫솔질을 해본 적이 있지만이 오류의 원인이나 해결 방법을 찾는 이유를 알아낼 수 없습니다. 이것을 체계적으로 디버깅하는 방법은 무엇입니까?

감사

편집

내 컨트롤러 액션는 다음과 같이 : 그것은 respond_to 블록처럼 보이는

class PhotosController < ApplicationController 

    def index 

    @photos = Photo.all 
    respond_to do |format| 
     format.html # index.html.erb 
     format.xml { render :xml => @photos } 
     format.json { render :json => @photos.collect { |a| a.to_jq_upload }.to_json } 
     format.js { render :json => @photos.collect { |a| a.to_jq_upload }.to_json } 
    end 
    end 

    def show 
    @photo = Photo.find(params[:id]) 

    respond_to do |format| 
     format.html # show.html.erb 
     format.xml { render :xml => @photo } 
     format.json { render :json => @photo } 
     format.js 
    end 
    end 

    def new 
    @photo = Photo.new 

    respond_to do |format| 
     format.html # new.html.erb 
     format.xml { render :xml => @photo } 
     format.json { render :json => @photo } 
     format.js 
    end 
    end 


    def edit 
    @photo = Photo.find(params[:id]) 

    end 

    def create 
    @photo = Photo.new(params[:photo]) 

    respond_to do |format| 
     if @photo.save 
     format.html { 
        render :json => [@photo.to_jq_upload].to_json, 
        :content_type => 'text/html', 
        :layout => false 
       } 
     format.json { render :json => [ @photo.to_jq_upload].to_json } 
     format.js 

     else 
     format.html { render :action => "new" } 
     format.xml { render :xml => @photo.errors, :status => :unprocessable_entity } 
     format.json { render :json => [ {:error => "An error was encountered while processing your photos. Please try again."}], status: 304 } 
     format.js 
     end  
    end 
    end 



     def update 
    @photo = Photo.find(params[:id]) 

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

    # DELETE /assets/1 
    # DELETE /assets/1.xml 
    def destroy 
    @photo = Photo.find(params[:id]) 
    @photo.destroy 

    respond_to do |format| 
     format.html { redirect_to(photos_url) } 
     format.xml { head :ok } 
     format.json { render :json => true } 
     format.js 
    end 
    end 
    end 
+0

아무것도? – Stefan

+0

앱의 로그를 확인 했습니까? 나는 당신의 생산 유형을 모른다. heroku에는'heroku logs' 또는'heroku logs -n 500'이 500 줄을 검색합니다. – jdoe

+0

예, 나는 ActionView :: MissingTemplate이 (템플릿 사진/생성, 응용 프로그램을 누락'받고 있어요 /로 만들 {: 로케일 => [: EN] : 형식 => [: JS : HTML] : 핸들러 => [ : ERB : 빌더, :..? 커피]}'왜는이 부분 –

답변

7

템플릿 (기본 경우 렌더링을 시도하는 format.js 타격이다 옵션이 제공되지 않음).

사용중인 플러그인 jQuery를 파일 업로드가 respond_to 블록이 필요 보인다 당신은 내가 또한 높은 debugger를 추천 할 것입니다 다음

def create 
    @photo = Photo.new(params[:photo]) 

    if @photo.save 
     render :json => [ @photo.to_jq_upload].to_json 
    else 
     render :json => [{ :error => "An error was encountered while processing your photos. Please try again." }], :status => 304 
    end  
end 

멀리 얻을 수있는 데, 특정 JSON 응답을 요구하기 때문에 gem을 사용하면 응용 프로그램 내에서 중단 점을 설정할 수 있으므로 어떤 일이 발생했는지 더 잘 알 수 있습니다.

debugger 보석을 추가하려면 먼저 Gemfile에 보석을 추가하고 명령 줄에서 bundle install를 실행해야합니다. 그런 다음 중단 점을 설정할 코드 줄에 단어 debugger을 추가하기 만하면됩니다. 귀하의 경우에는, 당신이 마지막으로

def create 
    @photo = Photo.new(params[:photo]) 
    debugger 

    if @photo.save 
    # ... rest of code 

을 할 수있는, 당신은 --debugger 옵션으로 서버를 다시 시작해야합니다. JQuery와 파일 업로드가 게시물을 서버에 요청을 플러그인 할 때, 중단 점거야, 그리고 당신은 더 나은 무슨 일이 일어나고 있는지에 대한 아이디어를 얻을 수있는 코드를 통해 전달 된 PARAMS뿐만 아니라 단계를 분석 할 수 있습니다. 건배. 응용 프로그램의 로그에

+1

하면 선생님이 사람이다! 대답에 +1. 내가 할 수 있다면, 나에게 이것을 해결할 수있는 도구를 주었다. 고맙습니다. 저는 며칠 동안이 문제에 대해 의아해했습니다. –

+1

듣기 좋습니다. 해피 코딩 !! –