简体   繁体   English

ruby on rails将实例变量从视图传递给控制器

[英]ruby on rails passing an instance variable from view to controller

I have the follwoing form in my view : 在我看来,我有以下形式:

I have an instance variable @selected_folder somewhere above in this view 我在这个视图中的某个地方有一个实例变量@selected_folder

<%= form_for :workflow_selection, :remote => true, :method => "get", :url => {:action => "final_submission"} do |f| %>  

            <p> Check the workflows needed and then click on the button with folder name</p>

            <% @workflow_map[@selected_folder].each do |i| %> 

            <p><%= f.check_box(i)%> <%= f.label(i, i)%><br /><p>
            <% end %>

            <br />
            <p><%= f.submit @selected_folder%></p> 
            <% end %>

I want to label the submit button as just ' submit' and should still be able to pass the @selected_folder instance variable to the final_submission action mentioned in the form_for tag 我想将提交按钮标记为“ submit'并且仍然可以将@selected_folder实例变量传递给form_for标记中提到的final_submission操作

I tried various option like 我试过各种各样的选择

<%= form_for :workflow_selection, :remote => true, :method => "get", :selected_folder => @selected_folder
    :url => {:action => "final_submission"} do |f| %>  

i tried to create a select drop down and hide it from view but still trying it to pass once the submit button is clicked. 我试图创建一个选择下拉菜单并将其从视图中隐藏但仍然尝试在单击提交按钮后传递它。

and some more options.. 还有一些选择......

None of them worked 他们都没有工作

Please help. 请帮忙。

If you want to pass @selected_folder along in the form submission, you can add a hidden_field_tag. 如果要在表单提交中传递@selected_folder ,可以添加hidden_​​field_tag。

As per Rails documentation: 根据Rails文档:

hidden_field_tag(name, value = nil, options = {})

So in your case 所以在你的情况下

<%= hidden_field_tag 'selected_folder', @selected_folder %>

in the workflow_selection, selected_folder will be present in the form hash. 在workflow_selection中,selected_folder将出现在表单哈希中。

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

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