gpt4 book ai didi

ruby-on-rails - 更改 Simple_Form 提交按钮操作?

转载 作者:太空宇宙 更新时间:2023-11-03 18:10:17 25 4
gpt4 key购买 nike

我为我的 Rails 应用程序创建了以下 SimpleForm。我希望提交按钮获取在每个字段中选择的数据,并将其带到下一个屏幕。有谁知道如何更改 SimpleForm 提交按钮的属性?现在它似乎只是在创造一些东西?我对它的默认操作感到有点困惑。

<div class="infoheaders">1. Question
<%= simple_form_for @category do |f| %>
<%= f.collection_select(:title, Category.all, :title, :title) %>
<div class="grey-text-subheader">Device: (optional)</div>
<%= f.check_box :Apple %> <%= f.label "Apple" %> &nbsp; &nbsp;
<%= f.check_box :iPhone %> <%= f.label "iPhone" %> &nbsp; &nbsp;
<%= f.check_box :iPad %> <%= f.label "iPad" %> &nbsp; &nbsp;
<%= f.check_box :Mac %> <%= f.label "Mac" %> &nbsp; &nbsp;
<%= f.check_box :Android %> <%= f.label "Android" %><br><br>
<%= f.check_box :Samsung %> <%= f.label "Samsung" %> &nbsp; &nbsp;
<%= f.check_box :Microsoft %> <%= f.label "Microsoft" %>&nbsp; &nbsp;
<%= f.check_box :Windows %> <%= f.label "Windows" %> &nbsp; &nbsp;
<%= f.check_box :Google %> <%= f.label "Google" %>
<%= f.button :submit, 'Submit' %>
<% end %>
</div>

最佳答案

简单的 Action 形式可以改为 Action (使用'url'选项),例如我们想要的,

<div class="infoheaders">1. Question

<%= simple_form_for @category, :url => url_for(:action => 'your_action', :controller => 'your_controller'), :method => 'post' do |f| %>
<%= f.collection_select(:title, Category.all, :title, :title) %>

</div>
<div class="grey-text-subheader">Device: (optional)</div>

<%= f.check_box :Apple %> <%= f.label "Apple" %> &nbsp; &nbsp;
<%= f.check_box :iPhone %> <%= f.label "iPhone" %> &nbsp; &nbsp;
<%= f.check_box :iPad %> <%= f.label "iPad" %> &nbsp; &nbsp;
<%= f.check_box :Mac %> <%= f.label "Mac" %> &nbsp; &nbsp;
<%= f.check_box :Android %> <%= f.label "Android" %>
<br><br>
<%= f.check_box :Samsung %> <%= f.label "Samsung" %> &nbsp; &nbsp;
<%= f.check_box :Microsoft %> <%= f.label "Microsoft" %>&nbsp; &nbsp;
<%= f.check_box :Windows %> <%= f.label "Windows" %> &nbsp; &nbsp;
<%= f.check_box :Google %> <%= f.label "Google" %>
<%= f.button :submit, 'Submit' %>
<% end %>

</div>

在您的 Controller 中,您将获得通过表单发送的参数,

class Yourcontroller
def your_action
// render text: params and return false
if params[:category][:ipad].present?
@checked = params[:category][:ipad]
end
if params[:category][:ipad].present?
@checked = params[:category][:android]
end
if params[:category][:ipad].present?
@checked = params[:category][:samsung]
end
/* check the params and assign to the variables */
// render text: params[:category] and return false
end
end

现在创建一个 your_action.html.erb,您将在那里获得值。

<div>
The checked valus is <%= @checked %>
</div>

就是这样。

关于ruby-on-rails - 更改 Simple_Form 提交按钮操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35497537/

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