右边有符号的词是哈希键吗?

Is a word with symbols on the right side a hash key?

before_action :find_item, only: [:show, :edit, :update, :destroy]

link_to "Delete", item_path(@item), method: :delete, data: { confirm: "Are you sure?"}

不知道右边带符号的是什么词:

only: ...

method: ..., data: ...

表示。我知道这些是方法的参数,但如果这些是散列键,我不知道为什么没有花括号。

当您使用散列作为方法的最后一个参数时,Ruby 允许您省略花括号,这使参数列表看起来更漂亮。这些电话转化为

before_action(:find_item, {only: [:show, :edit, :update, :destroy]})

<%= link_to("Delete", item_path(@item), {method: :delete, data: { confirm: "Are you sure?"}}) %>

词前带:的词只是符号 后面有它的是带有值

的符号
method: :delete

在此示例中,method 具有(空)符号的值 :delete 这相当于将其写为 { :method => :delete }