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
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top