DropDown选择到控制器操作

DropDown选择到控制器操作

本文介绍了Rails:DropDown选择到控制器操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Good Day,我有这个窗体view / startseites / index.html.erb和我在我的people_controller指定一个methode,她不去。我准备了一些幽灵代码来了解。我想给下拉列表中的条目添加button_to标签到控制器动作checkValid。在那里,我想验证数据库的条目。我必须从表中读取和写入。我希望它很清楚。

Good Day, i have this form view/startseites/index.html.erb and i specified a methode in my people_controller, she doesnt go. I prepared some ghost code for understanding. I want to give the entries from dropdowns with the button_to tag to the controller action checkValid. There i want to validate the entries against the database. I have to read and write from and to the table. I hope its clearly enough.

 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
   ...

view / startseites / index.html.erb:this code does not go

view/startseites/index.html.erb: this code doesnt go

这应该发送下拉选择到控制器动作checkValid()。

this should send the drop down selection to the controller action checkValid(). how can i use parameters?

 <%=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>

我已将此行添加到我的路线

i added this line to my routes

  match '/people/checkValid', :controller => 'people', :action => 'checkValid'

但是:没有路由匹配{:controller =>people / checkValid,:method =>:checkValid}

but: No route matches {: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"


推荐答案

缺少模板错误是指缺少视图。您应该在 app / views / people / 目录中有 check_valid.html.erb 查看文件。

The Missing template error refers to a missing view. You should have check_valid.html.erb view file in app/views/people/ directory.

此外,在应用程序目录中的命令行上运行 rake routes 。您将收到一个列表由routes.rb文件生成的路由。您可以仔细检查是否存在 people#checkValid

Also, run rake routes on the command line anywhere within your app's directory. You will receive a list routes that are generated by your routes.rb file. You can double-check there if people#checkValid exists.

Btw,您可能想将 checkValid 更改为 check_valid 因此您遵循Rails中操作的命名约定。

Btw, you might want to change checkValid to check_valid so you follow the naming convention for actions in Rails.

这篇关于Rails:DropDown选择到控制器操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:25