首页 \ 问答 \ 将text_field_tag用户输入和参数传递给rails中的控制器操作(Passing both a text_field_tag user input and a parameter to a controller action in rails)

将text_field_tag用户输入和参数传递给rails中的控制器操作(Passing both a text_field_tag user input and a parameter to a controller action in rails)

我正在使用aws-sdk和ruby以及rails来尝试创建一个工具,用于在亚马逊网络服务(aws)的“平面”文件结构中的任何位置上传文件夹

现在我有一个表单和id喜欢使用它来传递一个值以及输入到text_field_tag的用户输入。我的表单如下:

<h2>Create a Folder</h2>
  <%= form_tag({:action => 'create_folder'}, multipart: true) do %> 
  Please enter the folder name you wish to create: 
 <%= text_field_tag 'foldername' %>
  <br/> 
  <%= submit_tag 'Enter' %> <br />
 <% end %>

所以在我的控制器#action(即create_folder)中,我将使用params [:foldername]访问用户输入

表单是相应操作(索引)中索引视图的一部分,我正在访问实例变量并修改它们并尝试将它们与用户输入的'foldername'一起传递给create_folder操作。 假设mdofication的结果是'value', *我如何在单击submit *时将'value'和'foldername'传递给我的create_folder操作 。 我非常欣赏这方面的想法和看法。

该值是通过从包含表单视图的操作中修改实例而获得的字符串。

例如:如果我的索引操作有@variable - 我在视图中将其修改为value = @variable +“testvalue”,然后需要将此值与text_field_tag用户输入一起传递给另一个操作,方法是单击Enter按钮(甚至没有点击)

谢谢


Im working with the aws-sdk and ruby and rails to try and create a tool for uploading folders anywhere in the 'flat' file structure of amazon web services (aws)

Right now I have a form and id like to use it to pass a value along with the user input thats entered into the text_field_tag .My form is as follows:

#
<h2>Create a Folder</h2>
  <%= form_tag({:action => 'create_folder'}, multipart: true) do %> 
  Please enter the folder name you wish to create: 
 <%= text_field_tag 'foldername' %>
  <br/> 
  <%= submit_tag 'Enter' %> <br />
 <% end %>
#

So in my controller#action(i.e. create_folder) , I would access the user input using params[:foldername]

The form is part of an index view in the corresponding action (index) of which I am accessing instance variables and modifying them and trying to pass them to the create_folder action along with user inputted 'foldername'. Assuming the result of the mdofication is 'value' , *how would I pass both 'value' and 'foldername' to my create_folder action on clicking submit*. id really appreciate thoughts and views on this.

The value is a string obtained by modifying an instance from the action in which the view of the form is contained.

so for example: if my index action has a @variable -- I modify it in my view as value = @variable + "testvalue" and then need to pass this value alongwith the text_field_tag user input to another action on clicking the Enter button(or even without clicking )

Thanks


原文:https://stackoverflow.com/questions/18036770
更新时间:2022-11-23 16:11

最满意答案

您可以使用hidden_​​field_tag并在表单中提交您的值。

在控制器中,您应该出于安全原因检查此值。


You could use a hidden_field_tag and submit your value there within the form.

In the controller you should check this value because of security reasons..

相关问答

更多
  • 你有一个向后的表名。 HABTM按字母顺序查找模型。 仔细看看错误。 它说无法找到posts_tags。 您创建tags_posts。 所以将表名更改为posts_tags。 You have the table name backwards. HABTM looks for the models alphabetically. Look at the error carefully. It says posts_tags cannot be found. You create tags_posts. So ...
  • 问题出在这一行 <%= select_tag "skip_option", options_for_select([ "Yes", "No" ], "No"), id: "skip_option", :onchange => "reason_picker()" %> reason_picker()将是未定义的 要修复它,你可以像这样轻松地重构你的javascript: