【问题标题】:Pass params for other method为其他方法传递参数
【发布时间】:2016-04-07 17:26:44
【问题描述】:

当我进行搜索时,我的 url 结果是:

/refinanciamentos/index?utf8=✓&pesquisa_func_cpf=**111.111.111-11**&pesquisa_func_matricula=&commit=Pesquisar

然后显示所有搜索结果,我点击按钮:

<%= link_to 'Reserva', refinanciamentos_reserva_refinanciamento_path, :class => 'btn btn-primary' %>

这个按钮转到其他视图和其他方法。 如何在同一控制器中为其他方法传递搜索参数(pesquisa_func_cpf=111.111.111-11)? 搜索的方法是索引,我需要传递方法reserva_refinanciamento的参数,如何制作?我对此一无所知=/

---------- UDPDATE: 这是我的控制器

      def index
        if params[:pesquisa_func_cpf].present?
          @funcionarios = Funcionario.pesquisa_cpf(params[:pesquisa_func_cpf]).all
          @autorizacoes = Autorizacao.pesquisa_func_cpf(params[:pesquisa_func_cpf]).all
(...)


  def reserva_refinanciamento
   # nothing here 

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 rails-4-2-1


    【解决方案1】:

    你可以这样做

    <%= link_to 'Reserva', refinanciamentos_reserva_refinanciamento_path(:pesquisa_func_cpf => params[:pesquisa_func_cpf]), :class => 'btn btn-primary' %>
    

    然后在reserva_refinanciamento方法中可以通过params[:pesquisa_func_cpf]获取搜索数据。

    【讨论】:

    • 但方法 reserva_refinanciamento 不搜索。此方法是保存表单数据的响应,搜索参数将仅以相同方法显示在视图中
    • 你的意思是保存后想要将搜索参数传递给其他方法/动作?
    • 示例...我有一个方法 index = my seach,此方法为方法 reserva_refinanciamento 传递参数,此方法接收参数并在视图中显示并在表单上注册
    • 你能在这里添加你的控制器吗?
    • 在方法 reserva_refinanciamento 我把这个:@funcionario = Funcionario.pesquisa_cpf(params[:pesquisa_func_cpf]) 我的观点是: 但不工作。得到这个错误 undefined method `pessoa' for
    猜你喜欢
    • 2018-07-06
    • 2016-12-31
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-17
    • 1970-01-01
    相关资源
    最近更新 更多