Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何根据以前的表单选择显示简单的表单输入字段?_Ruby On Rails_Forms - Fatal编程技术网

Ruby on rails 如何根据以前的表单选择显示简单的表单输入字段?

Ruby on rails 如何根据以前的表单选择显示简单的表单输入字段?,ruby-on-rails,forms,Ruby On Rails,Forms,我有一个简单的表单字段 <%= f.input :plan_type, collection: Plan::PLAN_TYPES %> 和另一个输入_字段,如果上面字段中选择的选项是X,我必须仅显示 我尝试了以下方法,但无论其他字段中的选择是什么,都会显示输入字段: <% if f.object[:plan_type] != Plan::PLAN_TYPES.last %> <%= f.input :discount_amount, input_html:

我有一个简单的表单字段

<%= f.input :plan_type, collection: Plan::PLAN_TYPES %>

和另一个输入_字段,如果上面字段中选择的选项是X,我必须仅显示

我尝试了以下方法,但无论其他字段中的选择是什么,都会显示输入字段:

<% if f.object[:plan_type] != Plan::PLAN_TYPES.last %>
  <%= f.input :discount_amount, input_html: { min: 0 } %>
<% end %>


我需要在没有任何JS参与的情况下解决这个问题。非常感谢您的帮助。

我需要在不涉及任何JS的情况下解决此问题。祝你好运。如果你需要根据用户在表单中进行更改而不提交字段来显示/隐藏它。。。你必须使用JS。