def index
@workouts = Workout.all
@user_workouts = current_user.workouts.order("created_at DESC") unless current_user.blank?
if @client.present?
@user_workouts = @client.workouts.order("created_at DESC")
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: @workouts }
end
end
這個問題在這裏是實例變量@user_workouts
- 我使用嵌套的路線能夠做/像客戶端/ 1 /鍛鍊而不是/鍛鍊,這將顯示當前用戶的鍛鍊,如果這是嵌套將是/用戶/ 1 /鍛鍊。有沒有一種更習慣的方式來處理Rails中的這個控制器邏輯?
任何處理這種情況的慣用方法,或者只是讓條件變得很正常嗎?
看起來很漂亮,謝謝。 – 2013-03-11 04:57:16