【问题标题】:ArgumentError: Ajax::Pacientes#obtener_datos_paciente is not a supported controller nameArgumentError: Ajax::Pacientes#obtener_datos_paciente 不是受支持的控制器名称
【发布时间】: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


    【解决方案1】:

    最简单的解决方法是将控制器重命名为: class PacientesController &lt; ApplicationControllermatch"ajax/pacientes/:rut" =&gt; "pacientes#obtener_datos_paciente"

    如果您的控制器必须存在于Ajax 命名空间中,那么它也应该有一个命名空间路由。可以在this answer 中找到一个示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      • 2012-11-13
      • 1970-01-01
      • 2014-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多