私はとrespond_to
のブロックを持つRails 4アクションを持っています。しかし、ログには2回レンダリングされていますhtmlやその他のjson.iの原因は何ですか?また、id属性は[object object]
という単純な文字列を送信した後であっても、サーバーログにParameters: {"id"=>"[object Object]"}
のように表示されています。Rails 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]"}
これは良い兆候ではないと思います。これにより、私のサーバーは本当に必要のないデータを処理してしまいます。
コントローラアクションのコード –
にコード構造が追加されていれば有益かもしれません.... @ MuhammadIbraheem – Milind