Gareth Burrows
Gareth Burrows

Reputation: 1182

Routing in rails 3 - no route matches

I have a model called EmployeeTrainingCourse. This is a record of employee training, and all works fine. However, I am trying to setup a mechanism for inputting bulk training at once. So I have a link through to a get action on the employee_training_courses controller, which passes in several employee_ids, and then loads a form. I am then trying to have that form post to a different action on the employee_training_courses controller to actually create all the forms. Hope that makes sense.

The problem is that the form is not "finding" the route. Can someone help out?

Here are the routes

  get '/training_update', :to => 'employee_training_courses#training_update', :as => 'training_update'
  put '/process_training_update', :to => 'employee_training_courses#process_training_update', :as => 'process_training_update'

and here is a chopped up version of the employee_training_courses controller

class EmployeeTrainingCoursesController < EmployeesMainController
  def training_update
    @employees = @current_account.employees.where(:id => params[:employee_id])
    @course = EmployeeTrainingCourse.new
    render :training_update
  end

  def process_training_update
    do stuff in here
  end
end

and finally the form itself on the "training_update" haml page

  = simple_form_for [@course], :url => url_for(:action => 'process_training_update', :controller => 'employee_training_courses',), :method => 'post' do |f|
    = f.input :name, :label => 'Title'
    = f.submit

all that happens when i click submit is that I receive an instant routing error "No route matches "/process_training_update""

and in the server console it reports

Started POST "/process_training_update" for 127.0.0.1 at 2014-10-21 13:04:01 +0100
ActionController::RoutingError (No route matches "/process_training_update"):

appreciate some advice. I think it's something to do with the form but beyond that I do not know. Normally the training controller would get a single employee passed back to it, but in this case that's not happening.

Upvotes: 0

Views: 43

Answers (1)

apneadiving
apneadiving

Reputation: 115541

You're declaring put in your routes and using post in your view.

So replace:

put '/process_training_update'

with

post '/process_training_update'

Upvotes: 2

Related Questions