美好的一天,我有这个表单 view/startseites/index.html.erb 并且我在我的 people_controller 中指定了一个方法,她没有去。我准备了一些幽灵代码以供理解。我想将带有 button_to 标记的下拉列表中的条目提供给控制器操作 checkValid。我想在数据库中验证条目。我必须在桌子上读写。我希望它足够清楚。
class PeopleController < ApplicationController
def checkValid
@trainerName = params[:trainer_name]
@sportlerName = params[:sportler_name]
@trainerPID = params[:trainer_pid]
@sportlerPID = params[:sportler_pid]
#checks if sportlerID is null
@person = Person.find(params[:sportler_pid])
id = Person.sportler_id
if id = nil then
Person.sportler_id = params[:trainerPID]
else
puts "Sportler can have only one Trainer!"
end
end
...
查看/startseites/index.html.erb:这段代码不走
这应该将下拉选择发送到控制器操作 checkValid()。我如何使用参数?
<%=button_to( "Zuordnung erstellen", :action => "checkValid", :controller =>"people" %>**
<table>
<tr>
<td colspan="3">
Jeder Sportler kann ein Trainer haben. </br>
</td>
</tr>
<tr>
<td>Trainer</td>
<td>
<%= collection_select(:trainer, :trainer_id, Trainer.all, :id, :name) %>
</td>
<td>
<%= link_to 'Neuer Trainer', new_person_path(:type => "Trainer") %>
</td>
<tr>
<tr>
<td>Sportler</td>
<td>
<%= collection_select(:sportler, :sportler_id, Sportler.all, :id, :name) %>
</td>
<td>
<%= link_to 'Neuer Sportler', new_person_path(:type => "Sportler") %>
</td>
<tr>
<tr>
<td></td>
<td></td>
<td>
**<%=button_to( "Zuordnung erstellen", :action => "checkValid", :controller => "people") %>**
</td>
<tr>
</table>
我将此行添加到我的路线
match '/people/checkValid', :controller => 'people', :action => 'checkValid'
但是:没有路由匹配 {:controller=>"people/checkValid", :method=>:checkValid}
不,我认为它会发生,但是
模板丢失
Missing template people/checkValid, application/checkValid with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "C:/Users/jord/testmood/app/views"