【发布时间】:2021-11-19 22:17:10
【问题描述】:
我正在使用项目中的回收代码,但在这个版本中我没有得到很好的结果。
我使用 Rails 5.2.2 和 RVM Ruby 2.7.1
我需要使用这个函数来调用一个ajax并传递一个客户端已经存储的数据并填写一个表格,数据将通过每个客户端的RUN搜索
我不明白为什么 match() 对我不起作用
控制人员
class Ajax::PacientesController < ApplicationController
layout nil
def obtener_datos_paciente
#usuario = params[:rut]
usuario = Usuario.first :rut => params[:rut]
puts usuario.inspect.yellow
if usuario.nil?
render :json => {
:exito => true,
:mensaje => "No existen registros asociados al rut #{params[:rut]}."
}
else
render :json => {
:exito => true,
:es_empresa => true,
:mensaje => "El paciente con rut #{params[:rut]} ya existe.",
:data => {
:id => usuario.id,
:rut => usuario.rut,
:primer_nombre => usuario.primer_nombre,
:segundo_nombre => usuario.segundo_nombre,
:apellido_paterno => usuario.apellido_paterno,
:apellido_materno => usuario.apellido_materno,
:direccion => usuario.direccion,
:ciudad => usuario.ciudad,
:comuna => usuario.comuna,
:telefono => usuario.telefono,
:email => usuario.email
}
}
end
rescue Excepciones::DatosNoExistentesError => e
flash.now[:info] = e.message
render :json => { :mensaje => e.message }
end
end
路线
match(
"ajax/pacientes/:rut" => "ajax::pacientes#obtener_datos_paciente",
:as => :obtener_datos_paciente,
:via => :get
)
控制器Usuario
require 'json'
class UsuariosController < ApplicationController
helper_method :url_paciente
def index
@usuarios = Usuario.all
end
def ingreso_paciente
end
def registrar_ingreso
end
def ingresar_ficha_kinesica
alias url_paciente obtener_datos_paciente_ajax_pacientes_path
end
end
【问题讨论】:
标签: ruby-on-rails activerecord routes ruby-on-rails-5