简体   繁体   中英

Problem passing params from view to controller in Ruby On Rails

I am new to ROR and am trying to pass two variables from two fields in a view to a controller to generate a dataset for an excel export. The excel export works, however all I get are headers and no data. I know it's because the parameters aren't being passed to the controller.

Here's the code. The SQL has been shortened... In View

    <table border="0" cellspacing="0" cellpadding="10">
      <tr>
        <td style="text-align: left; width:400px;"> Enter any part of a BU Manager Name, Subcontractor name, Subcontractor ID, PO Number, CRN or SCA name:</td>
        <td style="text-align: left;">
          <% form_tag  :controller => 'subcontracts', :action => 'show_active_subcontracts_results', :method => 'get' do %>
            <p>
              <%= text_field_tag :search, params[:search] , :id => 'search_field' %>
            </p>
        <td>
            <p>
              Expand Contract Period:
              <%=  select_tag 'c_end_date', options_for_select([["Current Subcontracts", "1"],["Past 5 Years", "2"], ["All", "3"]],{:mutiple => false}) %>
              <%= submit_tag "Update", :name => nil %>
              <%= link_to_function "Clear", "$('search_field').clear()" %>
              <%= link_to 'Export To Excel',:action=>'active_subcontracts_to_excel',  :format=> 'excel'  %>

              </p>
        </td>
          <% end %>
        </td>            
      </tr>          
    </table>

What I want to do is pass the 'c_end_date' and 'search' data to the controller. Not sure if the link_to is the correct way.

Thank you for your help.

Your html is invalid: between the td above your form tag you're starting another td inside the form tag where the opening td hasn't been closed yet. This could be breaking your form. Try taking that td out entirely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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