简体   繁体   English

Active Admin侧边栏从文本输入中获取价值

[英]Active Admin Sidebar get value from text input

I'm trying to create a simple sidebar in the :index view of an Active Admin resource that has a two text inputs and button. 我正在尝试在具有两个文本输入和按钮的Active Admin资源的:index视图中创建一个简单的边栏。 I have the button trigger a collection_action when pressed, but I can't figure out how to get the values of both inputs into into the collection_action. 我按下按钮时会触发collection_action,但是我不知道如何将两个输入的值都输入到collection_action中。 Below is my partial that I render for my sidebar: 以下是我为侧边栏渲染的部分内容:

<form accept-charset="UTF-8" action="/admin/earned_points" class="filter_form" id="new_e" method="get">
  <div class="filter_form_field filter_string search">
    <label class="label" for="email">Email:</label>
    <input type="text" id="email" />
  </div>
  <div class="filter_form_field filter_string search">
    <label class="label" for="filename">File Name:</label>
    <input step=any" type="text" id="fileName" placeholder="EarnedPointData" />
    <a href=<%= export_admin_earned_points_path(controller.params) %>>
      <input style="margin-top:15px" type="submit" id="Export" value="Export"/>
    </a>
  </div>
</form>

I seldom do web development so I apologize if this seems like an extremely basic questions. 我很少进行网络开发,因此如果这看起来是一个非常基本的问题,我深表歉意。 Any help would be greatly appreciated. 任何帮助将不胜感激。

Thank you 谢谢

UPDATE: 更新:

Turns out that my structure was all bad. 原来我的结构很糟糕。 Thanks to nistvan for pointing out that I should be able to just pull them out form the params. 感谢nistvan指出我应该能够将它们从参数中拉出来。 From that I realized that I needed to setup my form better. 从那时起,我意识到我需要更好地设置表单。 I ended up use embedded ruby to do this. 我最终使用嵌入式红宝石来做到这一点。 Below is my final partial. 下面是我最后的部分。

<%= form_tag export_admin_earned_points_path, method: :get do %>
    <%= label_tag(:email, "Email:") %>
    <%= text_field_tag(:email, nil, placeholder: 'your@email.com' ) %>
    <%= label_tag(:filename, "File Name:") %>
    <%= text_field_tag(:filename, nil, placeholder: 'EarnedPointsData') %>
    <%= submit_tag("Export") %>
<% end %>

You can reach the passed parameters in the controller_action via the params (hash) variable. 您可以通过params(hash)变量在controller_action中获取传递的参数。 You can check how the params looks like if you raise an error in the controller action: 如果在控制器操作中引发错误,则可以检查参数的外观:

raise params.inspect

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM