我無法理解Create Method上的雙渲染錯誤。創建時的雙渲染錯誤
問題是Create Method必須重定向到一個非特定的對象,因爲Create Method的對象有一個多態類(Commentary - Commentable)。
我想創建一個評論,將它鏈接到一個對象(Appointment,Person,...),並重定向到該對象(redirect_to @objeto),而不是評論索引。我該怎麼辦?
代碼(comentarios_controller.rb)主要是:
def create
#Verifica o objeto
@objeto = nil
tipo = params[:comentable_type]
case tipo
when "Comercial::Oportunidade"
@objeto = Comercial::Oportunidade.find_by_id(params[:comentable_id])
when "Comercial::Compromisso"
@objeto = Comercial::Compromisso.find_by_id(params[:comentable_id])
end
@comentario=Comercial::Comentario.new(params[:comercial_comentario])
@comentario.organizacoes<<current_empresa
@comentario.usuario = current_usuario
create! do |success, failure|
if success
@objeto.comentarios << @comentario
flash[:success] = I18n.t 'activerecord.successful.messages.created.m', :model => @comentario.class.model_name.human
redirect_to @objeto
else
flash.discard
end
end
end
使用Rails 3.2.2
哪裏是創建代碼! ? – 2014-12-04 17:18:32
它來自InheritedResources(https://github.com/josevalim/inherited_resources)。 – Laerte 2014-12-04 18:22:51