Reputation: 17480
My app is a workout scheduler.
The client typically does workouts at one of three timeslots in a given day, so I'm providing a quick-add function to schedule a morning, noon or evening workout.
I have the code working, but I don't think I'm doing it the right way.
My route is as follows:
match 'workouts/quick_add/:date/:timeslot' => "workouts#quick_add",
:as => 'workout_quick_add'
Which I use via something like this:
<%= link_to 'Morning Workout', workout_quick_add_path(:date => day, :timeslot => 'morning') %>
Now, this works, if the request comes in over GET, but that doesn't seem right based on the HTTP Protocol method definitions. It seems like POST or PUT would be right, but if I add :via => :post
or :put
to the route, the whole thing buggers out with a routing error.
What's correct here, and what's the right way to implement this kind of a function?
Upvotes: 0
Views: 557
Reputation: 3409
How about:
resources :workouts do
collection do
post :quick_add
end
end
And pass date and timeslot in params.
Upvotes: 2