Ruby on rails 4 在使用内联方法执行操作之前

Ruby on rails 4 在使用内联方法执行操作之前,ruby-on-rails-4,Ruby On Rails 4,我正在我的控制器中尝试 before_action { authorize @user }, except: [:index] 并得到以下错误 syntax error, unexpected ',', expecting keyword_end (SyntaxError) before_action { authorize @user }, except: [:index]

我正在我的控制器中尝试

before_action { authorize @user }, except: [:index]
并得到以下错误

syntax error, unexpected ',', expecting keyword_end (SyntaxError) before_action { authorize @user }, except: [:index]
                                                                                                    ^
当我使用

before_action { authorize @user }
它很好用。我的问题是如何向此行添加
除:
子句

谢谢


Matt

您还可以使用do…end指定块

   before_action except: [:index] do
      authorize @user
   end

也可以使用do…end指定块

   before_action except: [:index] do
      authorize @user
   end
你可以做:

before_action except: [:index] { authorize @user }
如果需要,也可以使用array,例如:

before_action except: [:index, :edit] { authorize @user }
你可以做:

before_action except: [:index] { authorize @user }
如果需要,也可以使用array,例如:

before_action except: [:index, :edit] { authorize @user }

使用Ruby>=2.5.0时,您需要在\u操作之前执行:
(除了:[:索引,编辑]){authorize@user}
使用Ruby>=2.5.0时,您需要在\u操作之前执行:
(除了:[:索引,编辑]){authorize@user}