Ruby on rails 将多个选定参数传递给提交链接
我有一个尝试自动提交到后端的设置。有3个不同的下拉框,具有用户可选择的参数。我是这样建立我的网站的(所有的“脚手架”):Ruby on rails 将多个选定参数传递给提交链接,ruby-on-rails,ruby,Ruby On Rails,Ruby,我有一个尝试自动提交到后端的设置。有3个不同的下拉框,具有用户可选择的参数。我是这样建立我的网站的(所有的“脚手架”): classxsearch“搜索”%> 我也尝试过使用submit_标签。我不知道如何在我的控制器中触发一个方法(如果它应该在控制器中?因为它来自我假设放在这里的浏览器),该方法具有从每个集合中选择的值 简而言之:我如何获取每个集合的选定值并将其传递给函数?该函数应放在何处(在控制器或.html.erb文件中) 谢谢,这让我抓狂。我最终采用了一种新的方法来解决这个问题。这是我
classxsearch
每个条目/文件/参数在其模型中都有“归属于:xsearch”
xsearch的index.html.erb具有以下功能:
<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" %>
光谱提交者
选择要搜索的数据库
选择要使用的参数文件
选择要搜索的光谱文件(或文件夹)
“X搜索”,操作=>“搜索”%>
我也尝试过使用submit_标签。我不知道如何在我的控制器中触发一个方法(如果它应该在控制器中?因为它来自我假设放在这里的浏览器),该方法具有从每个集合中选择的值
简而言之:我如何获取每个集合的选定值并将其传递给函数?该函数应放在何处(在控制器或.html.erb文件中)
谢谢,这让我抓狂。我最终采用了一种新的方法来解决这个问题。这是我给其他正在搜索的人的代码。此脚本的目的是允许其他用户通过授权用户向集群提交搜索
<%= 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>
<ul>
<% @xsearch.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% 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>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
我相信所有的变量都应该是复数的——参数、频谱文件和熵
<%= 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>
<ul>
<% @xsearch.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% 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>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
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"
end
if (@recurse == 'Yes')
@recurse = 1
else
@recurse = 0
end
@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 rscript.sh %s %s %s %s %d' % [@database['name'], @spectrafile['name'], @paramfile['name'], @email, @recurse])
@xsearch = Xsearch.new(:database => @database['name'], :parameters => @paramfile['name'], :spectra => @spectrafile['name'])
respond_to do |format|
if @xsearch.save
format.html { redirect_to @xsearch, notice: 'Search was successfully created.' }
format.json { render json: @xsearch, status: :created, location: @xsearch }
else
format.html { render action: "new" }
format.json { render json: @xsearch.errors, status: :unprocessable_entity }
end
end
end
end