0

こんにちは、私はこのフォーム 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
   ...

view/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"
4

1 に答える 1

1

このMissing templateエラーは、ビューが欠落していることを示しています。check_valid.html.erbディレクトリにビューファイルが必要ですapp/views/people/

また、rake routesアプリのディレクトリ内の任意の場所でコマンド ラインで実行します。routes.rb ファイルによって生成されたリスト ルートを受け取ります。存在するかどうかを再確認できpeople#checkValidます。

ところで、 Rails のアクションの命名規則に従うように変更checkValidすることをお勧めします。check_valid

于 2013-02-10T15:06:05.833 に答える