0
두 개체 사이의 연결을 만들고 데이터베이스에 변경 내용을 저장하려고했습니다. 나는 통지에 객체에 대한 호출을 포함 시켰습니다. 객체에 대한 호출을 포함 시켰습니다. 업데이트가 실제로 데이터베이스에서 발생했는지 확인하기 위해 아무 것도 변경되지 않았는지 확인합니다.레일 : 저장 후 데이터베이스가 업데이트되지 않음
requests_controller.rb
class RequestsController < ApplicationController
before_filter :load_requestable
def accept
@request = Request.find(params[:id])
@request.profile.send("#{@belongs_to}=",@requestable)
if @request.save
redirect_to [@requestable, :requests], notice: "Request Accepted #{@request.profile.send("#{@belongs_to}").name}"
else
render :new
end
end
private
def load_requestable
klass = [Company, Profile].detect { |c| params["#{c.name.underscore}_id"]}
@requestable = klass.find(params["#{klass.name.underscore}_id"])
@belongs_to = klass.to_s.downcase
end
end
레일 여기 폭포 - 저장해야한다 (I 모르겠어요)? 어쨌든, 프로필을 직접 저장해보십시오 ('if @ request.profile.save'). –
그 트릭을 했어, 그 대답으로 제출할 수 있습니까? –