내 레일 3.2 프로젝트에서 컨트롤러에 show_html
기능이 있습니다. 데이터베이스에 특정 URL이있는 사이트를 찾을 수 있으면 해당 URL이보기로 전달됩니다. 그렇지 않으면, 나는 그것이 내가 그것을 테스트 http://www.google.com레일 : 컨트롤러에서 리디렉션
def show_html
site_list = Site.where(:url => params[:url])
if site_list.length > 0
site = site_list.first
else
redirect_to "http://www.google.com"
end
@html = site.html
render "show_html.html.erb"
end
및 site_list.length > 0
로 리디렉션 할, 그것을 작동합니다. 그러나 site_length_list = 0
일 때 오류 undefined method 'html' for nil:NilClass
가 발생합니다. 왜 그것은 else
진술에 들어가서 google.com
을 렌더링하지 않습니까?
을 정의합니다. – uday