[英]Rails routes.rb proper syntax for resources :users
I am wanting to do these two routings... but I can't figure out the proper syntax... I am pretty new at rails. 我想要做这两个路由......但是我无法弄清楚正确的语法......我在rails上很新。
resources :users do
get :increase_workouts, on: :collection
end
resources :users do
get :increase_workoutseconds, on: :collection
end
This doesn't seem to work. 这似乎不起作用。
Basically, I am trying to use ajax to call on a ruby controller action to update my model like this. 基本上,我试图使用ajax调用ruby控制器动作来更新我的模型。
function alertFunc() {
if(jwplayer().getState() == "playing" && timeWatched < duration){
timeWatched++
$.ajax("/users/increase_workoutseconds")
} else if (timeWatched >= duration){
clearInterval(theInterval);
}
else {
clearInterval(theInterval)
}
}
The action is in the users controller under the increase_workouts action. 该操作位于increase_workouts操作下的用户控制器中。 I am also trying to call the increase_workoutseconds action.
我也试图调用increase_workoutseconds动作。 Hence, the two different attempts to do the resources :users do.
因此,两种不同的尝试来做资源:用户这样做。
I figured out how to do it. 我想出了怎么做。 I am still learning how routes work in rails, but looks like this was an easier way to do it.
我仍然在学习如何在rails中使用路由,但看起来这是一种更简单的方法。
get '/users/increase_workoutseconds', to: 'users#increase_workoutseconds'
get '/users/increase_workouts', to: 'users#increase_workouts'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.