2014-01-10 5 views
0

페이지를 redirect_to하지 않습니다, 양식 (생활 잘) 오류에 그러나오류 성공

원격으로 제출하고 올바르게 index.js.erb를로드합니다 (다른 사람이) 아무 반응이 없습니다. 오류시 다른 파일을로드하거나 index.js.erb에 논리를 추가하고 싶습니다. 그러나, 그냥 실패하고로드되지 않습니다.

오류 자원을로드하지 못했습니다 : 서버가 구조

(을 구현 한 후 나는 그것이 아무튼 때문에 즉 이해, 내가 406 오류가 발생 알고 500 (내부 서버 오류)의 상태으로 대응 't은 이벤트를 찾을 수 있습니다,하지만 난 다시 사용자)

이벤트 컨트롤러를 알리는 모달를 표시 할 수 있도록 내가 보장 어떻게 내 index.js.erb-를로드

def index 
    respond_to do |format| 
    if @event = Event.find_by_event_code(params[:checkin]) 
     format.html { redirect_to @event, success: "You have found your event" } 
     format.js 
    elsif @event = Event.find_by_speaker_code(params[:checkin]) 
     format.html { redirect_to @event, success: "Welcome Super User. You have found your event" } 
     format.js 
    else 
     format.html { redirect_to @event, error: "No event by that event code" } 
     format.js 
    end 
    end 
end 
,691,363 (210)

index.js.erb

$("#checkin-popup").remove(); 
$("#checkin-confirm-popup").html("<%= escape_javascript(render("/events/index.html.erb")) %>") 
$('#checkin-confirm-popup').modal('show'); 

button.html

<%= simple_form_for @event, remote: true ,:method => 'get' do |e| %> 
    <div class="talknumber"><%= text_field_tag :checkin, params[:search] %></div> 
    <%= e.button :submit, "Checkin", :class => "btn btn-default" %> 
<% end %> 

서버 로그

Started GET "/events?utf8=%E2%9C%93&checkin=1212122&commit=Checkin" for 127.0.0.1 at 2014-01-10 11:43:39 -0500 
Processing by EventsController#index as JS 
    Parameters: {"utf8"=>"✓", "checkin"=>"1212122", "commit"=>"Checkin"} 
    (0.5ms) SELECT "users"."name" FROM "users" 
    Event Load (0.5ms) SELECT "events".* FROM "events" WHERE "events"."event_code" = 1212122 ORDER BY events.created_at ASC LIMIT 1 
    Event Load (0.4ms) SELECT "events".* FROM "events" WHERE "events"."speaker_code" = 1212122 ORDER BY events.created_at ASC LIMIT 1 
Completed 406 Not Acceptable in 7ms (ActiveRecord: 1.4ms) 

답변

0

당신이 호출이있는 경우 구조 블록을

def index 
    respond_to do |format| 
     begin 
     if @event = Event.find_by_event_code(params[:checkin]) 
      format.html { redirect_to @event, success: "You have found your event" } 
      format.js 
     elsif @event = Event.find_by_speaker_code(params[:checkin]) 
      format.html { redirect_to @event, success: "Welcome Super User. You have found your event" } 
      format.js 
     end 
     rescue 
     format.html { redirect_to @event, error: "No event by that event code" } 
     format.js 
     end 
    end 
    end 
+0

안녕하세요, 이제 구조 블록 시작을 시도했습니다. 이제 406 오류가 발생합니다. http : // localhost : 3000/events? utf8 = % E2 % 9C % 93 & 체크인 = dawdw12 & 커밋 = Checkin 406 (Not Acceptable) – RedRory

+0

@ RedRory는 디버거에 익숙하십니까? 너 구출 블록에서 흐름을 멈추고 확인해 줄래? – arun15thmay

+0

디버거를 설치하고 2 행에 배치했습니다. 그러나 "다음"을 시도 할 때. 그것은 나를 active_record/relation.rb와 다른 고수준의 방법으로 옮기고 말 그대로 "20 배로"넥서스하고 내 인덱스 작업에 결코 오지 않습니다. – RedRory

0

을 시작하십시오 너의 경쟁에서 w 그 @event를 참조하십시오 그럼 당신은 그들과 거래해야합니다. 페이지에 값을 제출하는 양식이 있다면,보기가 @event = Event.new과 함께 제공되는지 만 확인하면됩니다. 그러나 아마도 그렇지 않을 것이므로 @event가 정의되지 않은 경우 페이지 컨텍스트 내에서 의미있는 대체 값을 제공하여 뷰 단계에서 구조를 작성하려고합니다. 뭔가 같이 :

<%= @event ? @event : 'No event' %> 

보다는

<%= @event %> 

편집 : 새로운 컨트롤러 코드

def index 
respond_to do |format| 
    if @event = Event.find_by_event_code(params[:checkin]) 
     format.html { redirect_to @event, success: "You have found your event" } 
     format.js 
    else 
     if @event = Event.find_by_speaker_code(params[:checkin]) 
     format.html { redirect_to @event, success: "Welcome Super User. You have found your event" } 
     format.js 
     else 
     format.html { redirect_to @event, error: "No event by that event code" } 
     format.js 
     end 
    end 
    end 
end 

난 정말이 비록 일을하는 좋은 방법입니다 생각하지 않습니다. 당신이 쿼리 할 수있는 별개의 매개 변수를 얻을 수 있도록 양식을 분리해야합니다 (예 : params.has_key? :foo). 그러면 그 반대의 경우도 마찬가지입니다.

<%= simple_form_for @event, remote: true ,:method => 'get' do |e| %> 
    <div class="talknumber"> 
    <%= text_field_tag :event_code, params[:search] %> 
    <%= text_field_tag :speaker_code, 'value here - I don't know what params[:search is] %> 
    </div> 
    <%= e.button :submit, "Checkin", :class => "btn btn-default" %> 
<% end %> 

이 당신이 params.has_key? :event_code이 false 인 경우, 다음 params.has_key? :speaker_code을 찾아 말할 수있는 방법, 그리고, 다른 분기를 실행하는 것이 실패.

+0

이것은 마음에 떠 올랐습니다. 일시적으로 색인을 변경했습니다 .js.erb to alert ("테스트"); 따라서 <% @event %>의 로딩은 일어나지 않습니다. – RedRory

+0

오,'@ event'는'index.js.erb'에서 사용되지 않고 있습니까? 귀하의 경고는 클라이언트 측에서만 발생하며, 그 전에 서버가 오작동하고 있음을 기억하십시오. –

+0

디버깅 목적으로 index.js.erb에서 모든 것을 제거하고 이제는 경고 만 호출합니다. (그냥 오류가 발생하면 파일을 호출하려고합니다). 불운. 내 ELSE (10 번 줄) 이후에있을 수 있다면 "@event"[우리가 알고있는]로 리디렉션하려고하거나 format.html을 건너 뛰고 곧바로 format.js로갑니다. – RedRory