2017-12-10 3 views
2

respond_to 블록이있는 레일 4 작업이 있습니다.하지만 로그에 두 번 렌더링됩니다. html 및 기타 json.i에 대한이 무엇입니까 궁금해.이 id 속성은 [object object] 심지어 서버 로그에 Parameters: {"id"=>"[object Object]"} 같은 간단한 문자열을 보낸 후에 오는 것입니다.레일 4 - 내 컨트롤러 동작이 로그에서 볼 수있는 것처럼 html과 json 응답을 모두 실행하는 이유

###my route code 

    get 'halls/:id' => 'home#show_by_location', as: :show_by_location 

    ####my homecontroller code 

    def show_by_location  

    if params[:id] and params[:id].present? 

     ##get only halls address as addressable 
     @filter_results_found = false 
     if params[:capacity].present? 
     ####some business logic added 
     @result = ##GETTING SOME RESULT HERE 
     if @result.size == 0 
      flash.now[:notice] = "No details found" 
     end 
     end 
     if params[:food_type].present? 
     ###some business logic added 
     @result = ##GETTING SOME RESULT HERE 
     if @result.size == 0 
      flash.now[:notice] = "No halls found in #{@show_by_parameter.capitalize} that allow only #{food_type}" 
     end 
     end 

     if params[:rating].present? 
     @result = ##GETTING SOME RESULT HERE 
     flash.now[:notice] = "No details found in #{@show_by_parameter.capitalize} with rating of #{rating} star(s)" if @halls.size == 0 
     end 
     if params[:pricing].present? 
     @result = ##GETTING SOME RESULT HERE 
     end 
    end 
     if @filter_results_found === false 
     @result = ##GETTING SOME RESULT HERE 
     end   
     @result = @result.paginate(:page => params[:page]) 

    end 



    ####development/server log 

    Started GET "/halls/Sydney" for 43.242.228.212 at 2017-12-10 07:28:11 +0000 
    Cannot render console from 43.242.228.212! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 
    Processing by HomeController#show_by_location as HTML 
     Parameters: {"id"=>"Sydney"} 

     ########other logs removed..... 
     ......... 
     ...again below is json rendering for same action 




    Started GET "/halls/[object%20Object]" for 43.242.228.212 at 2017-12-10 07:28:24 +0000 
    Cannot render console from 43.242.228.212! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 
    Processing by HomeController#show_by_location as JSON 
     Parameters: {"id"=>"[object Object]"} 

내가 이것이 좋은 징조라고 생각하지 않습니다이 정말 필요하지 않은 동일한 데이터를 처리하기 위해 내 서버를 발생합니다.

+0

컨트롤러 동작 코드 –

+0

에 코드 구조가 추가 된 경우 유용 할 수 있습니다 .... @ MuhammadIbraheem – Milind

답변

0

결국 나는 문제점이 무엇인지 알아 냈습니다. 누군가 비슷한 문제에 직면 할 수 있도록 게시하고 있습니다.

문제 난이 플러그인의 기존 이미지/비디오를로드하는 데 필요한 스크립트에서 아약스 (JSON) 호출이있는 go.Now, 이미지, 동영상을 업로드 내 양식에 jquery fileupload plugin을 사용하고

그 페이지. 따라서 스크립트가으로로드되고 매니페스트 - application.js.So에 js 파일이 추가되면 모든 요청이 스크립트에서 + json 호출로 호출되면 항상 ajax를 호출합니다.

솔루션

나는 JS 파일을 제거하고 그것은 또한 개별적으로 대신의 스크립트를로드 할 수 assets.rb에 새 항목을 추가 포함 needed.This 만 양식 페이지에 명시 적으로 포함해야 자산 파이프 라인. 이제 문제가 해결

<%= javascript_include_tag "jQuery-File-Upload-9.11.2/video_upload", :media => "all" %> 

너무 또한 형태의 파일 업로드 플러그인으로 작업 로그에의 한 요청 - JS에 필요한 템플릿 파일 포함

Rails.application.config.assets.precompile += %w(video_upload image_upload) 

희망이 있으면 도움이됩니다.

관련 문제