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]"}
내가 이것이 좋은 징조라고 생각하지 않습니다이 정말 필요하지 않은 동일한 데이터를 처리하기 위해 내 서버를 발생합니다.
컨트롤러 동작 코드 –
에 코드 구조가 추가 된 경우 유용 할 수 있습니다 .... @ MuhammadIbraheem – Milind