0
스카 폴딩을 통해 생성 된 '생성'경로에 대한 POST 요청을 수행하려고합니다. 컨트롤러 이름은 'Translation'이고 생성 경로는 '/ translation'입니다. 이를 위해 jQuery로 ajax 요청을 만들었다. 내 요청은 다음과 같습니다. -jQuery, Rails 및 Ajax 데이터베이스에 대한 POST
데이터에 내 패러미터가 포함되어 생성 된 변환에 이러한 값이 포함되기를 원합니다. 번역의 매개 변수는 '출처'와 '산출물'입니다. 발판에 의해 생성, 변환 컨트롤러 '생성'방법은 같습니다 -
def create
@translation = Translation.new(params[:translation])
respond_to do |format|
if @translation.save
format.html { redirect_to(@translation, :notice => 'Translation was successfully created.') }
format.xml { render :xml => @translation, :status => :created, :location => @translation }
else
format.html { render :action => "new" }
format.xml { render :xml => @translation.errors, :status => :unprocessable_entity }
end
end
end
나는 데이터에 다른 값을 삽입하려고 아직 그들에게 적용되지 않습니다. 새 번역이 작성되지만 매개 변수는 없습니다.
data: {'source':'hello'}
data: "source=hello"
data: {translations:{'source':'hello'}}
레일 폼을 사용하는 방법을 알고 있지만 여전히 jQuery를 사용하고 싶습니다. 나는 자바 스크립트 함수를 루비로 번역하는 것을 게으른 것으로 생각했다. 시간이 많이 걸렸다. 어쨌든, 그것은 작동합니다, 고마워요 :) – Ariel