ubuseral
ubuseral

Reputation: 427

Rails: DropDown Selection to Controller Action

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 doesnt go

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'

but: No route matches {:controller=>"people/checkValid", :method=>:checkValid}

no i think it goes but

Template is missing

 Missing template people/checkValid, application/checkValid with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "C:/Users/jord/testmood/app/views"

Upvotes: 0

Views: 1021

Answers (1)

Gjaldon
Gjaldon

Reputation: 5644

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

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, you might want to change checkValid to check_valid so you follow the naming convention for actions in Rails.

Upvotes: 1

Related Questions