레일을 통해 컨트롤러 적용 (def create)을 사용하여 뷰 적용 / 인덱스의 Ajax 게시물을 통해 내 사용자와 정보를 생성하고 있습니다.
노선 :
resources :jobs, :only => [:show, :index, :create] do
resources :apply, :only => [:index, :create]
resources :share, :only => [:index, :create]
end
레이크 루트 :
job_apply_index:
GET /jobs/:job_id/apply(.:format) apply#index
POST /jobs/:job_id/apply(.:format) apply#create
변경 전 상황 : Ajax to Post를 사용 하지 않고 rails post를 사용 했을 때 . 양식을 올바르게 작성하면 양식이 보기 / 적용 / 만들기 페이지 로 리디렉션됩니다 .
현재 상황 : 형태 :
<%= form_tag job_apply_index_path(@job.sap_id), :class => "apply", :multipart => true, :remote => true, :name => "ajaxform", :id => "ajaxform" do %>
apply.js. 커피 :
$("#register_button").on 'click', (e) ->
e.preventDefault()
$('#ajaxform').submit()
$("#ajaxform").submit (e)->
e.preventDefault()
postData = $(this).serializeArray()
formURL = $(this).attr("action")
$.ajax
url: formURL
type: "POST"
data: postData
success: (data, textStatus, jqXHR) ->
$("#loadingSpinner").fadeOut "slow"
handle_messages data
error: (jqXHR, textStatus, errorThrown) ->
#todo
handle_message :
handle_messages = (msg_list) ->
console.log msg_list
$("#errorTitle").empty()
$("#errorList").empty()
if msg_list.errors
#TODO
else if msg_list.notice
#TODO
else if msg_list.redirect
window.location.replace msg_list.redirect_url
else
alert "not good son"
apply_controller의 내 응답 :
# Respond with error messages
if @user.errors.full_messages.any? || @user.personal_info.errors.full_messages.any?
errors_msg = @user.errors.full_messages + @user.personal_info.errors.full_messages
errors_msg.map! {|error| {message: error}}
msg = {:errors => errors_msg, :title => I18n.t('validation_header', :errors => errors_msg.count)}
elsif notice_msg
msg = {:notice => notice_msg}
else
msg = {:redirect => true, :redirect_url => "path_to_job_create"}
end
# Pass redirect params
respond_to do |format|
format.json { render :json => msg }
format.html { render action: "index" }
format.js
end
목표 : 사용자가 모든 것을 올바르게 입력 한 후보기 / 적용 / 만들기로 리디렉션하고 싶습니다. 아약스를 사용하기 전과 동일합니다.
더 많은 정보가 필요하십니까? 그냥 물어봐!
아래 문제의 경우
Mark는 37 Signals에서 일자리를 지원합니다. 그는 / jobs에서 시작합니다. 그는 채용 공고를 찾았습니다. 37 명이 개발자를 찾고 있습니다.
그는 클릭하고 / jobs / 37-signals / index로 이동하여 채용 정보를 찾고 지원 양식을 찾습니다. 경로 : jobs / 12345 / index, 리소스 : jobs / : job_id / index
작업 양식 제출은 / jobs / 12345 / create에 대한 POST 요청을 생성합니다.
모델이 유효한 경우 두 가지 옵션은 다음과 같습니다.
Javascript를 사용하여 페이지를 업데이트하십시오. 플래시 검증. 양식을 제거하고 서버에서 반환 된 요약 데이터가있는 새 html 템플릿으로 교체하고 콜백 성공 메서드에 전달했습니다.
요약 컨트롤러로 리디렉션하고보기를 렌더링합니다. 경로에서 'jobs / : id / summary'를 추가하고 'apply # summary'를 추가하고 Apply # summary 메서드를 추가합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다