【发布时间】:2016-11-04 11:45:45
【问题描述】:
show.html.erb
<h1><%= @script.Name %></h1>
<%= simple_form_for @script , :url => script_execute_path do |f| %>
<%= f.input :mainDirectory %>
<%= f.input :customFilePath %>
<%= f.button :submit, 'Run' %>
<% end %>
routes.rb
root :to => "scripts#index"
resources :scripts do
get "execute"
end
型号
class AddNameToScript < ActiveRecord::Migration
def change
add_column :scripts, :Name, :string
add_column :scripts, :Description, :text
end
end
execute 是我添加的自定义操作,我想从 show 转到该操作。
routes.rb
...
script_execute GET /scripts/:script_id/execute(.:format) scripts#execute
...
但我收到一个错误
No route matches {:action=>"execute", :controller=>"scripts", :id=>"1"}
missing required keys: [:script_id]
但是为什么我需要[:script_id]?这不是一个自定义操作,我可以定义我想要的方式吗?这里缺少什么以及如何传递[:script_id]?
【问题讨论】:
-
您能否将此命令的输出 -
rake routes | grep execute- 添加到您的问题中?这将显示execute方法期望的参数(如果有)。 -
@jeffdill2:现在
标签: ruby-on-rails routing routes rails-routing