在我的 Contro-6ren">
gpt4 book ai didi

ruby-on-rails - 将参数发送到 submit_tag rails 上的 Controller

转载 作者:行者123 更新时间:2023-12-04 06:18:45 27 4
gpt4 key购买 nike

我的表单上有两个 submit_tag,我想在每个上发送不同的参数。
我怎样才能做到这一点?

我的表单 View :

<%= form_tag(some_path, :method => "get") do %>
<%= text_field_tag :number %>
<%= text_field_tag :name %>
<%= submit_tag "Op01", class: "btn_search", my_parameter: 1 %>
<%= submit_tag "Op02", class: "btn_search", my_parameter: 2 %>
<% end %>

在我的 Controller 上:
@oper_type = params[:my_parameter]

但是当我显示@oper_type 时,它​​总是为零。

谢谢。

最佳答案

<%= submit_tag "Op01", class: "btn_search", value: 1 %>
<%= submit_tag "Op01", class: "btn_search", value: 2 %>

@oper_type = params[:commit] # 1 or 2

或者更简单一点
<%= submit_tag "Op01", class: "btn_search" %>
<%= submit_tag "Op01", class: "btn_search" %>

@oper_type = params[:commit] # "Op01" or "Op02"

关于ruby-on-rails - 将参数发送到 submit_tag rails 上的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16968740/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com