我最终通过使用 form_new 方法解决了这个问题。这是我的代码,供其他正在搜索的人使用。此脚本的目的是允许其他用户通过授权用户向集群提交搜索。
<%= 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 %>
以及控制器的 create: 方法中的相关位
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