Question

Hello I am new to haml and trying to figure out how to do something on a form.

I have an array of classes ["Basketball", "Baseball", "Football"]

From my sports index view I want to send a post to the SportsController create method with the name of the selected class as a param.

= options = Sports.all   #this is an array of the classes shown above
= form_for(@sport, url: sport_path) do |f|
  = options_for_select(options)
  = f.submit
Was it helpful?

Solution

It looks like you are just needing the proper method. If you are in the index page it has no idea what you are trying to do with the url: sport_path.

Try adding the method: :post so that the form knows to go to the create method in the sports controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top