Pass multiple selected parameters to a submission link

I have a setup attempting to automate submission to a backend. There are 3 different dropdown boxes with user-selectable parameters. I set up my website like this (all 'scaffolds'):

class Xsearch < ActiveRecord::Base
  has_many :xentry
  has_many :spectrafile
  has_many :parameter

Each entry/file/parameter has the belongs_to :xsearch in their model.

The index.html.erb of the xsearch has the following:

<h1>Spectra Submitter</h1>
<h2>Select a database to search</h2>
<%= collection_select("xpost", :id, Xentry.all(), :title, :name ) %>
<h2>Select a parameter file to use</h2>
<%= collection_select(:ppost, :id, Parameter.all(), :name, :name ) %>
<h2>Select a Spectra file (or folder) to search</h2>
<%= collection_select(:spost, :id, Spectrafile.all(), :name, :name ) %>
<%= link_to "Search", :controller => "xsearches", :action => "search" %>

I've tried using submit_tag as well. I have no idea how to trigger a method in my controller (if it should be in the controller? Since it's from the browser I assumed to put it here) that has the selected values from each collection_select.

So in short: How can I take the selected values for each collection_select and pass them to a function? Where should that function be placed (in the controller or in the .html.erb file)?

Thanks, this has been driving me crazy.


I ended up solving the issue by moving to a form_new method. Here's my code for anyone else who is searching. The purpose of this script was to allow other users to submit a search to a cluster through an authorized user.

<%= form_for(@xsearch) do |f| %>
  <% if @xsearch.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@xsearch.errors.count, "error") %> prohibited this xsearch from being saved:</h2>

      <% @xsearch.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
  <% end %>
    <div class="field">
      <h2>Pick A Database To Search</h2>
      <%= collection_select(:db, :id, @all_entries, :id, :name) %>
      <h2>Pick A Parameter File To Use</h2>
      <%= collection_select(:para, :id, @all_parameters, :id, :name) %>
      <h2>Pick a File or Folder To Search</h2>
      <%= collection_select(:sfile, :id, @all_spectrafiles, :id, :name) %>

  <div class="actions">
    <%= f.submit %>
<% end %>

And the relevant bit in the controller's create: method

def create
  @database = Xentry.find(params[:db][:id])
  @paramfile = Parameter.find(params[:para][:id])
  @spectrafile = Spectrafile.find(params[:sfile][:id])
  @recurse = params[:recurse]
  @email = params[:emailtag]
  if @email.empty?
    @email = "None"
  if (@recurse == 'Yes')
    @recurse = 1
    @recurse = 0
  @recurse = 0#disabled until kill methods are implemented
  @hostname = hostname
  @username = username
  Net::SSH.start(@hostname, @username) do |session|
    session.exec('source .bashrc')
    session.exec('sh %s %s %s %s %d' % [@database['name'], @spectrafile['name'], @paramfile['name'], @email, @recurse])
    @xsearch = => @database['name'], :parameters => @paramfile['name'], :spectra => @spectrafile['name'])
    respond_to do |format|
        format.html { redirect_to @xsearch, notice: 'Search was successfully created.' }
        format.json { render json: @xsearch, status: :created, location: @xsearch }
        format.html { render action: "new" }
        format.json { render json: @xsearch.errors, status: :unprocessable_entity }

Need Your Help

Binding TabControl ItemsSource to Collection of ViewModels

wpf xaml binding tabcontrol

For some reason I am having a heck of a time getting my TabControl to display properly when binding the ItemsSource to a ObservableCollection of view models. I'm basing my design off of the tutorial

Creating a JAR file and using it in Android Studio

java android android-studio jar

There are no good tutorials about creating a JAR file. I'm trying to create a JAR file and use it in different projects. I can create a class without an Activity as a library project in format of

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.